2013-05-14 9 views
6

Ho il seguente script PS scritto:Come faccio ad avere proprietà specifiche con Get-ADUser

Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | Export-CSV "ADUsers.csv"

Da quello che posso dire che dovrebbe essere solo tornando DisplayName. Comunque sta restituendo tutto. Il problema è che DistinguishedName sta causando problemi di troncamento più avanti nel mio processo. Come posso ottenere che lo script restituisca solo determinate proprietà?

risposta

8

utilizzando select-oggetto per expample:

Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | select -expand displayname | Export-CSV "ADUsers.csv" 
+1

hmmm ... che ha restituito un errore: ArgumnetNull.Microsoft.PowerShell.Commands. SelectObjectCommand. – kickinchicken

+0

Sto cercando la sintassi per Select-Object. Se funziona pubblicherò la sceneggiatura. – kickinchicken

+0

l'errore indica che l'utente nella pipe non ha impostato un displayname.Prova a rimuovere '-expand' –

4

Questo ha funzionato anche per me:

Get-ADUser -Filter * -SearchBase "ou=OU,dc=Domain,dc=com" -Properties Enabled, CanonicalName, Displayname, Givenname, Surname, EmployeeNumber, EmailAddress, Department, StreetAddress, Title | select Enabled, CanonicalName, Displayname, GivenName, Surname, EmployeeNumber, EmailAddress, Department, Title | Export-CSV "C:\output.csv"

Problemi correlati