This PowerShell script will generate a report based on source and target primary SMTP address.
Script
#
# Author - Santhosh Sivarajan
# Version - 1.0
Clear
$NAOUT = New-Item -type file -force "E:\Scripts\NA_PSTMP.txt"
"Samaccountname`tSPSMTP`tTPSMTP" | Out-File $NAOUT -encoding ASCII
Write-host "Samaccountname`tSPSMTP`tTPSMTP"
#############################################################################
#Source Domain
$ObjFilter = "(&(objectClass=person)(objectClass=User)(mail=*)(!(ObjectClass=contact)))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://DC=sivarajan,DC=com"
$AllObj = $objSearch.FindAll()
foreach ($Obj in $AllObj)
{
$userNA = [ADSI] $Obj.path
$objItemTNA = $userNA.Properties
$TmailNA = $objItemTNA.mail
$TsamNA = $objItemTNA.samaccountname
###################################################################################
#Target domain
$ObjFilterCWS = "(&(objectCategory=person)(objectCategory=User)(samaccountname=$TsamNA))"
$objSearchCWS = New-Object System.DirectoryServices.DirectorySearcher
$objSearchCWS.PageSize = 15000
$objSearchCWS.Filter = $ObjFilterCWS
$objSearchCWS.SearchRoot = "LDAP://DC=sivarajan2,DC=COM"
$AllObjCWS = $objSearchCWS.FindOne()
foreach ($ObjCWS in $AllObjCWS)
{
$userCWS = [ADSI] $ObjCWS.path
$objItemTCWS = $userCWS.Properties
$TmailCWS = $objItemTCWS.mail
}
#######################################################################################
"$TsamNA`t$TmailNA`t$TmailCWS"| Out-File $NAOUT -encoding ASCII -append
Write-host "$TsamNA`t$TmailNA`t$TmailCWS"
}
0 comments:
Post a Comment