私はpowershellに非常に慣れておらず、Windowsドメインの各コンピューターに移動してユーザープロファイルのサイズを取得するスクリプトを作成しています。私はpowershellスクリプトで以下を試しました
$profileDir = "\\$computerName\c$\users\userProfile"
$fullProfile = (Get-ChildItem $profileDir -recurse -force | Measure-Object -property length -sum)
ただし、一部のコンピューターでは、以下のエラーが発生します。問題は、プロファイルの一部のディレクトリに長いパスがあり、get-ChildItem
失敗しているようです
Get-ChildItem : The specified path, file name, or both are too long. The fully
qualified file name must be less than 260 characters, and the directory name mu
st be less than 248 characters.
At C:\scripts\powershell\profiles.ps1:56 char:30
+ $fullProfile = (Get-ChildItem <<<< $profileDir -recurse -force | Measure-Obj
ect -property length -sum)
+ CategoryInfo : ReadError: (\\computerName...nt.IE5\RQT4K4JU:St
ring) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChil
dItemCommand
##########################################################################################################################
この時点でdu.exe
、正常に動作する SysInternals の (diskusage) を使用してみましたが、出力をdu
変数に取り込む方法がわかりません。私は私のスクリプトに以下を持っています
$dirSize = .\du.exe -c c:\temp |convertFrom-csv | select-object DirectorySize
write-host $dirSize
出力は
PS C:\scripts\powershell> .\profiles.ps1
@{DirectorySize=661531}
出力をどのようにしたいか
PS C:\scripts\powershell> .\profiles.ps1
661531