Skip to content

Instantly share code, notes, and snippets.

/example.ps1 Secret

Created March 8, 2016 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/172a9d3aad4cdc323e6f to your computer and use it in GitHub Desktop.
Save anonymous/172a9d3aad4cdc323e6f to your computer and use it in GitHub Desktop.
$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