我还是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"
}
答案 0 :(得分: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"
}
答案 1 :(得分: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"
}