124909
Dec 03, 2015, updated at 12:35:14 (UTC)
1289
3
0
Powershell: Inhalt von 3 OUs in einer Tabelle ausgeben, sodass nicht bei jeder weiteren OU die Kopfzeile aufgelistet wird
Morgen,
Ich möchte die Informationen von 3 OU's in einer Tabelle ausgeben. Das Problem ist nur, dass mein Skript bei jeder einzelnen OU die Kopfzeile neu auflistet. Also wieder mit bspw. Vorname, Nachname und Beschreibung.
Ich möchte aber nur eine Kopfzeile und darunter dann der Inhalt der besagten 3 OUs. Ist dies prinzipiell möglich ?
Im Prinzip sieht der Teil der Abfrage zurzeit so aus:
$ous = @('OU=xxxs,DC=1,DC=2',
'OU=yyy,DC=1,DC=2',
'OU=zzz,DC=1,DC=2')
foreach ($ou in $ous)
{
$mailbodytext = Get-ADUser -SearchBase $ou -Filter * -Properties * | where {$_.AccountExpirationDate -le $days -and $_.AccountExpirationDate -ne $null} |
Select-Object @{Name="Account-Ablaufdatum:";Expression={$_.AccountExpirationDate.ToString("dd.MM.yyyy")}}, `
@{Name="Windows-Loginname";Expression={$_.Name}}, `
@{Name="Momentan aktiviert?";Expression={$_.Enabled}}, `
@{Name="Vorname:";Expression={$_.GivenName}}, `
@{Name="Nachname:";Expression={$_.Surname}}, `
@{Name="SAM:";Expression={$_.UserPrincipalName}}, `
@{Name="Beschreibung:";Expression={$_.Description}} |
Sort-Object -Property Account-Ablaufdatum | Format-Table -AutoSize
Ich möchte die Informationen von 3 OU's in einer Tabelle ausgeben. Das Problem ist nur, dass mein Skript bei jeder einzelnen OU die Kopfzeile neu auflistet. Also wieder mit bspw. Vorname, Nachname und Beschreibung.
Ich möchte aber nur eine Kopfzeile und darunter dann der Inhalt der besagten 3 OUs. Ist dies prinzipiell möglich ?
Im Prinzip sieht der Teil der Abfrage zurzeit so aus:
$ous = @('OU=xxxs,DC=1,DC=2',
'OU=yyy,DC=1,DC=2',
'OU=zzz,DC=1,DC=2')
foreach ($ou in $ous)
{
$mailbodytext = Get-ADUser -SearchBase $ou -Filter * -Properties * | where {$_.AccountExpirationDate -le $days -and $_.AccountExpirationDate -ne $null} |
Select-Object @{Name="Account-Ablaufdatum:";Expression={$_.AccountExpirationDate.ToString("dd.MM.yyyy")}}, `
@{Name="Windows-Loginname";Expression={$_.Name}}, `
@{Name="Momentan aktiviert?";Expression={$_.Enabled}}, `
@{Name="Vorname:";Expression={$_.GivenName}}, `
@{Name="Nachname:";Expression={$_.Surname}}, `
@{Name="SAM:";Expression={$_.UserPrincipalName}}, `
@{Name="Beschreibung:";Expression={$_.Description}} |
Sort-Object -Property Account-Ablaufdatum | Format-Table -AutoSize
Please also mark the comments that contributed to the solution of the article
Content-Key: 289962
Url: https://administrator.de/contentid/289962
Printed on: April 18, 2024 at 03:04 o'clock
3 Comments
Latest comment
$ous = @(
'OU=xxxs,DC=1,DC=2',
'OU=yyy,DC=1,DC=2',
'OU=zzz,DC=1,DC=2'
)
$ous | %{
$mailbodytext = Get-ADUser -SearchBase $_ -Filter * -Properties * | ?{$_.AccountExpirationDate -le $days -and $_.AccountExpirationDate -ne $null} | select @{Name="Account-Ablaufdatum";Expression={$_.AccountExpirationDate.ToString("dd.MM.yyyy")}}, `
@{Name="Windows-Loginname";Expression={$_.Name}}, `
@{Name="Momentan aktiviert?";Expression={$_.Enabled}}, `
@{Name="Vorname:";Expression={$_.GivenName}}, `
@{Name="Nachname:";Expression={$_.Surname}}, `
@{Name="SAM:";Expression={$_.UserPrincipalName}}, `
@{Name="Beschreibung:";Expression={$_.Description}}
} | Sort 'Account-Ablaufdatum' | Format-Table -AutoSize
Das Problem mit deinem Code war das du anstatt der Pipe-Syntax die ausführliche Syntax für die Foreach-Schleife von Powershell genutzt hast und die Ausgabe als formatierten String zurückgegeben hast anstatt die Objekte selber mit select.