我对 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