Im trying to get a list of sites from IIS (8.5) to include the folder size but cant get this to work.
Below is the current code i have that is working without the size
Import-Module webAdministration # Required for Powershell v2 or lower
$filepath = C:\sites.csv
$sites = get-website
foreach($site in $sites) {
$name = $site.name
$bindings = $site.bindings.collection.bindinginformation.split(":")
$ip = $bindings[0]
$port = $bindings[1]
$hostHeader = $bindings[2]
"$name,$hostHeader,$ip,$port" | out-host
"$name,$hostHeader,$ip,$port" | out-file $filePath -Append
}
I then attempted to add in this line
$size = Get-ChildItem -Directory -Force|ForEach {"{0,-30} {1,-30} {2:N2}MB" -f $_.Name, $_.LastWriteTime, ((Get-ChildItem $_ -Recurse|Measure-Object -Property Length -Sum -ErrorAction Stop).Sum/1MB)}
but that didnt work either.
I then attempted with
$size = Get-ChildItem $name + "\folderName\" | Measure-Object -Property Length -sum
which was getting closer but i think my syntax is wrong with $name + "\folderName\"
as im getting a series of errors. I say this is close as it has the path to the directory but it doesnt exist. The directory would exist if i can add the foldername to the $name variable?
Where am i going wrong? Or how could i retrieve the parent of each website folder size?