指定されたフォルダのフォルダサイズを報告できるスクリプトを作成しようとしています。get-childitem:存在しないためパス ''が見つかりません
フォルダ名を入力してもこのエラーが発生していますが、フォルダが存在することがわかりました。
また、このエラーが発生しない場合、私は常に0 MBを取得します。
get-childitem : Cannot find path 'C:\WINDOWS\system32\downloads' because it does not exist.
At C:\Users\Erik\Desktop\powershell script.ps1:58 char:12
+ $folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\WINDOWS\system32\downloads:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound, Microsoft.PowerShell.Commands.GetChildItemCommand
コード
$startfolder = Read-Host -Prompt 'Please enter the folder name:'
#check that input is not empty
if([string]::IsNullOrEmpty($startfolder)) {
Write-Host "folder name is NULL or EMPTY"
} else {
$folders = get-childitem $startfolder | where {$_.PSiscontainer -eq "True"}
"folder Name`tfolder Size (MB)"
foreach ($fol in $Folders) {
$colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
$size = "{0:N2}" -f ($colItems.sum/1MB)
"$($fol.name)`t$size"
}
}
問題はPowerShellセッションの実行アーキテクチャであり、そのフォルダがどこにあるかを示します。 c:\ windows \ syswow64 \ downloadsは何かを返しますか? – Matt