Checking MPS and AD Integrity... Part #2: User Objects - AD to MPS
Alright, first I provided the Powershell script to do MPS to AD check and now we are going to do the other way round, which is from AD to MPS. In this script, with the specified base DN, say OU=Hosting, DC=Fabrikam, DC=COM, it will start searching for all the user objects underneath that OU and then for each user object, it will extract the object GUID to see if it can mapped to an active customer ID in the MPS database. To run this, make the changes in the highlighted area, save this file to say ADtoMPS.ps1 and then run it. As with the previous script, it should also dump out a CSV file for your review.
So, have fun with it. :)
###########################################
if ($args[0] -eq $null) {
$LDAP = "ou=hosting, dc=fabrikam, dc=com"
} else {
$LDAP = $args[0]
}
$sqlserver = "MPSSQL01"
$sqldb = "PlanManager"
$sqlconnection = New-Object System.Data.SqlClient.SqlConnection
$sqlconnection.ConnectionString = "Server=$sqlserver;Database=$sqldb;Integrated Security = True"
$sqlcmd = New-Object System.Data.SqlClient.SqlCommand
$sqlcmd.connection = $sqlconnection
$sqladapter = New-Object System.Data.SqlClient.SqlDataAdapter
$dataset = New-Object System.Data.DataSet
function f([int]$a)
{
if ($a -lt 16) {
$r = "0" + [Convert]::ToString($a, 16)
} else {
$r = [Convert]::ToString($a, 16)
}
return $r
}
function GUID([String]$guid, [int]$dash)
{
$p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10,$p11,$p12,$p13,$p14,$p15 = $guid.split(" ")
$p0 = f($p0)
$p1 = f($p1)
$p2 = f($p2)
$p3 = f($p3)
$p4 = f($p4)
$p5 = f($p5)
$p6 = f($p6)
$p7 = f($p7)
$p8 = f($p8)
$p9 = f($p9)
$p10 = f($p10)
$p11 = f($p11)
$p12 = f($p12)
$p13 = f($p13)
$p14 = f($p14)
$p15 = f($p15)
if($dash -eq "0") {
$guid = $p0 + $p1 + $p2 + $p3 + "-" + $p4 +$p5 + "-" + $p6 + $p7 + "-" + $p8 + $p9 + "-" + $p10 + $p11 + $p12 + $p13 + $p14 + $p15
} else {
$guid = $p0 + $p1 + $p2 + $p3 + $p4 + $p5 + $p6 + $p7 + $p8 + $p9 + $p10 + $p11 + $p12 + $p13 + $p14 + $p15
}
return $guid
}
$domain = "LDAP://" + $LDAP
$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry $domain
$query = new-object system.directoryservices.directorysearcher
$query.SearchRoot = $directoryEntry
$query.PageSize = 1000
$query.filter = ("(objectClass=user)")
$users = $query.findAll()
$count = 0
$errorcount = 0
$select = ""
$dumpfile = "Username,ObjectGUID,MailboxGUID,PlanManagerMatch,MailboxGUIDMatch,Comment`n"
Foreach($user in $users)
{
$user = $user.GetDirectoryEntry()
$userDN = $user.distinguishedName
$userName = $user.name
"Username: " + $UserName
$userGUID = $user.objectGUID.ToString()
$objectguid = GUID $userGUID 0
$objectguid = $objectguid.ToLower()
"objectGUID: " + $objectguid
$userMailboxGUID = $user.msExchMailboxGuid.ToString()
$mailboxguid = GUID $userMailboxGUID 1
$mailboxguid = $mailboxguid.ToUpper()
if ($mailboxguid -ne "00000000000000000000000000000000") {
"MailboxGUID: " + $mailboxguid
} else {
"MailboxGUID: NULL"
}
# Match Customer Table
$sqlquery = "Select CustomerID FROM [PlanManager].[dbo].[Customers] WHERE StatusTypeCode = 'EN' and lower(CustomerID) = '" + $objectguid + "'"
$sqlcmd.CommandText = $sqlquery
$sqladapter.SelectCommand = $sqlcmd
$dataset.clear()
$justfill = $sqladapter.fill($dataset)
$items = $dataset.tables[0]
$query = $items | Select CustomerID
if ($query.CustomerID -ne $null) {
$CustomerID = $query.CustomerID.ToString()
# $CustomerID
$result = "Yes"
} else {
$result = "No"
}
$FoundPM = $result
"Found In PlanManager: " + $FoundPM
# Match Mailbox GUID
$sqlquery = "Select Asset FROM [PlanManager].[dbo].[CustomerAssets] WHERE StatusTypeCode = 'EN' and AssetTypeCode = 'EG' and lower(CustomerID) = '" + $objectguid + "'"
$sqlcmd.CommandText = $sqlquery
$sqladapter.SelectCommand = $sqlcmd
$dataset.clear()
$justfill = $sqladapter.fill($dataset)
$items = $dataset.tables[0]
$query = $items | Select Asset
if ($query.Asset -ne $null) {
$Asset = $query.Asset.ToString().ToUpper()
If($Asset -eq $mailboxguid) {
$result = "Yes"
$Asset = ""
} else {
$result = "No"
}
} else {
$result = "No Asset Found"
}
$FoundA = $result
"Match in Asset Table: " + $FoundA
# Output into CSV file
$comment = $Asset
$dumpfile = $dumpfile + $UserName + "," + $objectguid + "," + $mailboxguid + "," + $FoundPM + "," + $FoundA + "," + $comment + "`n"
" "
}
Set-Content "CheckUserADtoMPS.csv" $dumpfile
$sqlconnection.close()
###########################################
Comments
- Anonymous
February 14, 2016
hai, I just want to tell you that I am just very new to blogs and seriously loved this website. More than likely I’m planning to bookmark your blog post .
You amazingly come with really good posts. Thanks a lot for sharing your blog Microsoft.
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Palembang
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Papua
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Papua%20Barat
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Pati
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Pekalongan
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Pontianak
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Samarinda
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Semarang
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Serang
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Sidoarjo
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Surabaya
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Surakarta
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Tasikmalaya
http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Yogyakarta
http://www.lokerjobindo.com/search/label/Loker%20Jurusan%20Akunting
http://www.lokerjobindo.com/search/label/Loker%20Jurusan%20Asuransi
http://www.lokerjobindo.com/search/label/Loker%20Jurusan%20Teknologi%20Informasi
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Administrasi
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Akuntansi
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Alfamart
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Arsiparis
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Artis
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Astra
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Asuransi
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Auditor
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20BJB
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20BNI%20Syariah
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20BRI
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20Danamon
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20Mandiri
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20Indonesia
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20BCA
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20BTN
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank%20CIMB%20NIAGA
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20BUMN
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Terbaru
http://www.lokerjobindo.com - Anonymous
March 06, 2016
THANKS VERY MUCH
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-april-2016.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-mei-2016.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-juni-2016.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-juli-2016.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-agustus-2016.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-september.html
http://www.lokerjobindo.com/2015/10/info-lowongan-kerja-bulan-oktober-2016.html
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20BUMN
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20CPNS
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Terbaru
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Bank
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20SMA
http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20SMK
http://www.lokerjobindo.com
http://www.yacinta.com
http://www.kerjabumn.com
http://www.wisatasia.id/search/label/Wisata-Indonesia
http://www.wisatasia.id