2014-07-14 4 views
0

서버 목록에 큰 파일을 나열하는 다음 스크립트가 있습니다. 불행히도 그것은 아무것도 표시하지 않습니다. 그러나 $ _. 이름을 문자열 D : \로 바꾸면 제대로 작동합니다.Powershell에서 드라이브 변수가 작동하지 않습니다.

$servers = Get-Content "servers1.txt" | Select-String -pattern ` 
    "^[^#]" 
foreach ($line in $servers) { 
    $svr = echo $line | %{$_.Line.split(':')[2]} 
    Get-WmiObject Win32_Volume -ComputerName $svr -ErrorAction SilentlyContinue | 
    Select-Object __SERVER,Name | 
    foreach { 
     Invoke-command {Get-ChildItem -path $_.Name -rec | Where-Object ` 
     -FilterScript {($_.Length -ge 3GB) -and ($_.Name -notlike "*.mdf")}} -computername $svr 
    } 
} 

도움 주셔서 감사합니다.

답변

1

원격 명령 $ _에 범위 지정 문제가 있습니다. 이름이 존재하지 않습니다. 대신 다음을 시도하십시오.

Invoke-command { 
    param ($Path) 
    Get-ChildItem -path $Path -rec | Where-Object {($_.Length -ge 3GB) -and ($_.Name -notlike "*.mdf")} 
} -ComputerName $svr -ArgumentList $_.Name 
+0

잘 작동합니다. 매우 감사합니다! – user3835604

관련 문제