# Get folder properties from a collection of servers

**URL:** <https://forums.powershell.org/t/get-folder-properties-from-a-collection-of-servers/296>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-folder-properties-from-a-collection-of-servers/296 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-folder-properties-from-a-collection-of-servers/296/1 "2011-12-31T18:30:00Z")

</div>

by WilliamD at 2012-10-29 09:00:01

> Im new to powershell and need a little help. I have a script put together that does what I need it to do on a single server but I want it to query the folder properties of a collection of servers and include the servername in csv file. This is what I have so far:  
>   
> `$path = "c:\EVOfflineVault"$CsvFilePath = "C:\Windows\temp\EVOfflineFoldersReport.csv"Get-ChildItem $path |Where-Object {$.PSIsContainer} |% { $size = (Get-ChildItem $.FullName -recurse -force | Measure-Object -property length -sum -ErrorAction SilentlyContinue).sum $obj = New-Object PSObject Add-Member -inp $obj NoteProperty Name $.Name Add-Member -inp $obj NoteProperty Path $.FullName Add-Member -inp $obj NoteProperty Size $size $obj} | Sort-Object Size -Descending |Select-Object Name, @{N="Size(KB)";E={"{0:N2}" -f ($.Size / 1KB)} },Path |Export-CSV -Path $CsvFilePath -NoTypeInformation$file = $CsvFilePath$att = new-object Net.Mail.Attachment("$file")$msg = new-object Net.Mail.MailMessage$smtp = new-object Net.Mail.SmtpClient("mail.email.com",25)$msg.From = "email@blah.com"$msg.To.Add("email@blah.com")$msg.Subject = "EVOfflineCache Citrix Report"$msg.Body = "See Attached"$msg.Attachments.Add($att)$smtp.Send($msg)`

_by Jason\_Yoder\_MCT at 2012-10-29 15:59:29_

_> Hi William,  
>   
> You can use the Invoke-Command cmdlet to run your code remotely on other servers in your environment. The results will be returned to your client running the script. Here is an example:  
>   
> `$Servers = "Svr1", "Svr2", "Svr3"ForEach ($Server in $Servers){ Invoke-Command -Scriptblock { #<< Your code here >> } -ComputerName $Server}`  
>   
> Let me know if this helps.  
> Jason  
>   
>   
> }_

_by WilliamD at 2012-11-15 08:54:33_

> _That would leave me collecting reports from different servers instead of having them in one place. The simple way for a few static servers is to populate $path with all the server UNCs, e.g. "\server1\c$\EVOfflineVault", "\server\c$\EVOfflineVault" …_  
>   
> _Getting the servers from AD is a better choice so I went with:  
> `$erroractionpreference = "SilentlyContinue"$CsvFilePath = "c:\whatever"$dataColl = @()Import-Module ActiveDirectory$list = Get-ADComputer -SearchBase "OU=Citrix,OU=Servers,DC=blah,DC=Com" -Filter * | Select -Expand Nameforeach ($computer in $list){ Get-ChildItem "\$computer\c$\EVOfflineVault" | Where-Object {$.PSIsContainer} | % { $size = (Get-ChildItem $`_`.FullName -recurse -force | Measure-Object -property length -sum).sum $obj = New-Object PSObject Add-Member -inp $obj NoteProperty Name $.Name Add-Member -inp $obj NoteProperty Path $.FullName Add-Member -inp $obj NoteProperty Size $size $dataColl += $obj $obj } $dataColl | Sort-Object Size -Descending | Select-Object Name, @{N="Size(MB)";E={"{0:N2}" -f ($_.Size / 1MB)} },Path | Export-Csv -noTypeInformation -path $CsvFilePath}`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:58pm UTC](https://forums.powershell.org/t/get-folder-properties-from-a-collection-of-servers/296/2 "2024-05-16T20:58:06Z")

</div>


