0

私は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
4

1 に答える 1

1

あなたが持っているのはハッシュテーブルです。その値を取得するには、そのハッシュテーブル内のアイテムを参照する必要があります。それ以外の:

Write-Host $dirSize

試す:

$dirSize['DirectorySize']
于 2014-11-06T03:10:07.347 に答える