Come recuperare l'alias e -mail e CN per tutti in un gruppo di annunci utilizzando PowerShell

StackOverflow https://stackoverflow.com/questions/5861816

Domanda

Sto usando PowerShell con i CMDlet di ricerca.

Posso usare il cmdlet get-QadgroupMember per ottenere un elenco di tutti in un determinato gruppo. Fin qui tutto bene, ma vorrei anche ricevere il loro alias e -mail. Tutto ciò che viene restituito attualmente è qualcosa di simile:

Name      Type  DN
----      ----  --
Jane Doe  User  CN=Jane Doe,OU=Employee,DC=companyname,DC=com
Job Blow  User  CN=Joe Blow,OU=Employee,DC=companyname,DC=com

Ho provato a usare Get -Qaduser con il flag -IncludeallProperties, ma ottengo ancora solo i campi sopra restituiti e non so come ottenere i dati restituiti che la documentazione dice viene memorizzata nella cache sul computer.

Qualsiasi aiuto sarebbe apprezzato.

AGGIORNARE

Ho finito per usare "Seleziona" Simile al di sotto:

$everyone = Get-QADGroupMember "All employees" | select firstname, lastname, email

E questo ha ottenuto tutto ciò di cui avevo bisogno in una serie di hashtable. A quel punto è facile fare tutto il necessario tramite tutti con codice come:

for ($i=0; $i -le $everyone .length-1; $i++)
{
    write-host $everyone[$i].email
}

Mi ci è voluto un'eternità per trovare il "". Notazione per estrarre valori specifici dall'hashtable. Ho fatto l'analisi del testo e ha funzionato, ma sapevo che non poteva essere il modo giusto di farlo e alla fine ho trovato la documentazione sulla notazione del punto. Spero di documentare che qui salva qualcun altro un po 'di tempo!

È stato utile?

Soluzione

Sei sicuro che non restituisca queste informazioni? Hai provato a tubarsi il comando in Get-Member o Format-List -Force *? PowerShell può essere configurato per mostrare solo alcune proprietà degli elementi e non tutto ciò che potrebbe essere il caso qui.

È possibile selezionare le proprietà utilizzando Select-Object o solo select Se sei lì, sono lì, anche se PowerShell non li mostra per impostazione predefinita:

Some-Command | select Name, Type, DN, SomeOtherProperty

Puoi vederlo per esempio con Get-ChildItem anche:

PS Home:\> gci *.ps1


    Directory: C:\Users\Joey


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        2011-04-27     18:50        169 format.ps1
-a---        2011-04-26     18:36       1064 Untitled1.ps1
-a---        2011-04-27     18:41         69 x.ps1
-a---        2011-04-23     19:58         91 y.ps1

La normale invocazione produce solo quattro proprietà: Mode, LastWriteTime, Length e Name. Tuttavia, ce ne sono molti altri, come Get-Member Spettacoli.

PS Home:\> gci *.ps1|gm -MemberType Property


   TypeName: System.IO.FileInfo

Name              MemberType Definition
----              ---------- ----------
Attributes        Property   System.IO.FileAttributes Attributes {get;set;}
CreationTime      Property   System.DateTime CreationTime {get;set;}
CreationTimeUtc   Property   System.DateTime CreationTimeUtc {get;set;}
Directory         Property   System.IO.DirectoryInfo Directory {get;}
DirectoryName     Property   System.String DirectoryName {get;}
Exists            Property   System.Boolean Exists {get;}
Extension         Property   System.String Extension {get;}
FullName          Property   System.String FullName {get;}
IsReadOnly        Property   System.Boolean IsReadOnly {get;set;}
LastAccessTime    Property   System.DateTime LastAccessTime {get;set;}
LastAccessTimeUtc Property   System.DateTime LastAccessTimeUtc {get;set;}
LastWriteTime     Property   System.DateTime LastWriteTime {get;set;}
LastWriteTimeUtc  Property   System.DateTime LastWriteTimeUtc {get;set;}
Length            Property   System.Int64 Length {get;}
Name              Property   System.String Name {get;}

Altri suggerimenti

Ricordate che Object select scende l'oggetto e ne genera di nuovi.

Quindi in questo esempio:

$test = get-qaduser atestuser | select-object name

$ test sarà un pScustMobject (System.Object) contenente solo il nome.

Cosa vuoi fare con i dati? Output alla console ... a un file?

Farei qualcosa del genere:

get-qadgroupmember "domain users" | format-table name, displayname, email

O

get-qadgroupmember "domain users" | select-object name, displayname, email | Export-Csv c:\acsvfile.csv
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top