0
저는 powershell에 매우 익숙하며 Windows 도메인의 각 컴퓨터로 이동하여 사용자 프로필의 크기를 얻는 스크립트를 작성합니다. powershell 스크립트에서 아래에 시도했습니다.diskusage poweshell에서 사용하는 방법
$profileDir = "\\$computerName\c$\users\userProfile"
$fullProfile = (Get-ChildItem $profileDir -recurse -force | Measure-Object -property length -sum)
그러나 일부 컴퓨터에서는 아래 오류가 나타납니다. 문제는 프로필에 일부 디렉토리가 긴 경로를 가지고 get-ChildItem
내가 잘 작동 시스 인 터널에서 du.exe
(diskusage)를 사용하여 시도이 시점에서
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
을 입력하십시오. 내 스크립트에 아래에있는
$dirSize = .\du.exe -c c:\temp |convertFrom-csv | select-object DirectorySize
write-host $dirSize
출력은 I 출력이 어떤 도움을 크게 감상 할 수
PS C:\scripts\powershell> .\profiles.ps1
661531
처럼되고 싶은
PS C:\scripts\powershell> .\profiles.ps1
@{DirectorySize=661531}
입니다.
감사하지만 오류 PS C 이하로 얻을 : \ 스크립트 \ 파워 쉘> \ 형 System.Management의 객체로 색인 할 수 없습니다 profiles.ps1 .. Automation.PSObject입니다. C : \ scripts \ powershell \ profiles.ps1 : 7 char : 21 + 쓰기 호스트 $ dirSize [<<<< 'DirectorySize'] + CategoryInfo : InvalidOperation :(DirectorySize : String) [], RuntimeException + FullyQualifiedErrorId : CannotIndex – user1212915
OK, $ dirsize.directorysize를 시도하십시오. – TheMadTechnician
해시 테이블 주석이 나에게 단서를주었습니다. $ dirSize.DirectorySize를 시도했는데 출력이 예상대로되었습니다. PS C : \ scripts \ powershell>. \ profiles.ps1 661531 다시 한 번 감사드립니다! – user1212915