124909
Goto Top

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

Content-Key: 289962

Url: https://administrator.de/contentid/289962

Printed on: April 18, 2024 at 03:04 o'clock

Mitglied: 114757
Solution 114757 Dec 03, 2015 updated at 12:35:14 (UTC)
Goto Top
$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  
Gruß jodel32
Mitglied: 124909
124909 Dec 03, 2015 at 12:36:14 (UTC)
Goto Top
jodel32, ich verneige mich vor deinem schier unendlichen scheinenden Powershell-Horizont
Mitglied: 114757
114757 Dec 03, 2015 updated at 13:21:21 (UTC)
Goto Top
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.