0

我还是 PowerShell 的新手,并试图找出获取服务器上单个 Itunes 文件夹大小的最佳方法。有多个文件夹,它们都位于用户配置文件中。这是我到目前为止的脚本,但它没有显示所有单独的文件夹。

#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 之后忘记了 $i (在 foreach 循环中)(您想知道 $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 回答