-
-
Save anonymous/172a9d3aad4cdc323e6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SourceFile = (Import-Csv -Delimiter ";" -Path).DistinguishedName | |
#now $sourcefile is already smaller | |
foreach($User in $SourceFile) | |
{ | |
$HomeServer = Get-ADUser -Identity $User -Properties msExchHomeServer, DistinguishedName, userPrincipalName, mail, ObjectClass | |
#Try Get-AD-User, Get-ADObject and | |
#ADSI provider (see http://social.technet.microsoft.com/wiki/contents/articles/4231.working-with-active-directory-using-powershell-adsi-adapter.aspx) | |
#instead of Get-QADObject. Might perform better, might not. You have to test it. :) | |
#Always get only those properties that you'll need later! | |
If($HomeServer.msExchHomeServerName -eq 0) | |
#I think you don't need "Length" here, do you? | |
{ | |
[PSCustomObject]@{ | |
DistinguishedName = $HomeServer.DistinguishedName | |
userPrincipalName = $HomeServer.userPrincipalName | |
mail = $HomeServer.mail | |
ObjectClass = $HomeServer.ObjectClass | |
} | |
#Instead of selecting the required properties and writing it directly out to a CSV file, you are creating a PSObject in this case. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment