0

I'm still new to PowerShell and trying to figure the best way to get the size of individual Itunes folders on our server. There are multiple folders and they are all located in the user profiles. This is the script i have so far but it doesnt show all the individual folders.

#Gets a list of all itunes folders 
$dirOfItunes = dir  -Recurse -Filter "iTunes Media" -ErrorAction silentlycontinue

Write-Host "list of itunes folders found: " $dirOfItunes 
ForEach ($i in $dirOfItunes) 
{
   $UserItuneFolder = (Get-ChildItem -Recurse | Measure-Object -property length -sum)

   Write-Host "details of Itunes folders found:  " Write-Host $UserItuneFolder.get_Sum()

   write-host "folder name:  " $i.FullName

   "size " + "{0:N2}" -f ($UserItuneFolder.sum / 1MB) + " MB"
}
4

2 に答える 2

1

get-childitemの後に(foreachループで)$ iを忘れました($ iの合計サイズを知りたいですよね?)

これはあなたが望むことをするはずです:

#Gets a list of all itunes folders 
$dirOfItunes = dir  -Recurse -Filter "iTunes Media" -ErrorAction silentlycontinue

Write-Host "list of itunes folders found: " $dirOfItunes 
ForEach ($i in $dirOfItunes) 
{
   $UserItuneFolder = (Get-ChildItem $i.fullname -Recurse | Measure-Object -property length -sum)
   Write-Host "details of Itunes folders found:  " ([int] $UserItuneFolder.sum)
   write-host "folder name:  " $i.FullName
   "size " + "{0:N2}" -f ($UserItuneFolder.sum / 1MB) + " MB"
}
于 2012-01-04T15:29:17.423 に答える
0

コメントに十分なスペースがないため、これを回答として投稿するのが正しいことかどうかはわかりませんが、これは私が使用した最終的なコードです。問題の解決に協力してくれた jon Z に感謝します :-)

#Gets a list of all itunes folders 
$dirOfItunes = dir L:\Users\FolderRedirections -Recurse -Filter "iTunes Media" -ErrorAction silentlycontinue

#print list of folders found to the screen 
Write-Host "list of itunes folders found: "
ForEach ($A in $dirOfItunes) 
    {
    write-host "    " $A.fullname 
    }

#Get the total size of each folder 
ForEach ($i in $dirOfItunes) 
{
   $UserItuneFolder = (Get-ChildItem $i.fullname -Recurse | Measure-Object -property length -sum)
   Write-Host "Size of folders in bytes:  " ([int] $UserItuneFolder.sum)
   write-host "Folder name:  " $i.FullName
   "size of folder: " + "{0:N2}" -f ($UserItuneFolder.sum / 1MB) + " MB"

}
于 2012-01-05T11:56:33.643 に答える