Search code examples
powershellpowershell-2.0powershell-3.0

Add a Column to a Array


Hey Guys I have a Array with some Colums already inside. I add the rows with a Foreach loop with Get-Childitem. Now I need to put a command insde there so that I can get a other Row with the name that I already have in a other Variable added.

$Gesamt = foreach ($Names in $Pfad){
$Gesamt = $Pfad.name
Get-ChildItem -Path \\Server\users\z01\$($names)\*.pst , \\eServer\users\z01\$($names)\Archiv\*.pst , \\Server\users\z01\$($names)\Outlook\*.pst   | measure Length -sum

}

The Names are in $Pfad.names$ But it doesn't work that way...

$Pfad is created like that

$Pfad = Get-ChildItem \\Server\users\z01

Solution

  • Use Select-Object to create new objects with multiple properties (or "columns" if you will) based on existing objects:

    $Gesamt = Get-ChildItem \\Server\users\z01 |Select-Object Name,@{Name='TotalSize';Expression={ (Get-ChildItem -Path \\Server\users\z01\$($_.Name)\*.pst , \\eServer\users\z01\$($_.Name)\Archiv\*.pst , \\Server\users\z01\$($_.Name)\Outlook\*.pst   | Measure Length -Sum).Sum }}