2013-02-26 4 views
0

Powershell 3.0을 사용하는 멀티 렙 서버에 대해 아래를 실행하려고하지만 웬일인지 경로가 존재하지 않는다는 사실을 알고 있습니다.경로를 찾을 수 없습니까?

아이디어가 있으십니까?

CODE :

clear 
$computer = Get-Content -path c:\temp\servers.txt 

foreach ($computer1 in $computer){ 

Write-Host $computer1 
Get-Content -Path '\\$computer1\C$\Program Files\BMC Software\BladeLogic\RSCD\rscd.log' -Tail 10 

} 

ERROR :

SV191267 Get-Content : Cannot find path '\$computer1\C$\Program Files\BMC Software\BladeLogic\RSCD\rscd.log' because it does not exist. At C:\Users\gaachm5\AppData\Local\Temp\e4651274-dcab-4a87-95a6-0f11437a7187.ps1:7 char:1 + Get-Content -Path '\$computer1\C$\Program Files\BMC Software\BladeLogic\RSCD\rs ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (\$computer1\C$...c\RSCD\rscd.log:String) [Get-Content], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

SV193936 Get-Content : Cannot find path '\$computer1\C$\Program Files\BMC Software\BladeLogic\RSCD\rscd.log' because it does not exist. At C:\Users\gaachm5\AppData\Local\Temp\e4651274-dcab-4a87-95a6-0f11437a7187.ps1:7 char:1 + Get-Content -Path '\$computer1\C$\Program Files\BMC Software\BladeLogic\RSCD\rs ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (\$computer1\C$...c\RSCD\rscd.log:String) [Get-Content], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

+0

당신도 오류를 읽으려고 했습니까? 그렇게했다면 질문은 "왜 내 변수가 확장되지 않습니까?"였을 것입니다. . 이것은 거의 또는 전혀 노력을 보여줍니다. –

답변

4

시도 : 작은 따옴표 ' 변수에

"\\$computer1\C`$\Program Files\BMC Software\BladeLogic\RSCD\rscd.log" -Tail 10 

$에 대한 확장하지만 $computer1 리터럴로 취급되지 않습니다 $admin share은 이스케이프해야합니다. d 백틱으로`

+3

@ HungryHippos의 대답에서 지적한 바와 같이 관리자 공유를위한 달러 기호는 이스케이프 할 필요가 없기 때문에 \ char이 뒤따라 오지만 리터럴로 필요할 때 "문자열"에 달러 기호를 이스케이프 처리하는 것이 좋습니다. . –

+0

완벽하게 작동했습니다. - 감사합니다. – lara400

+0

@ lara400 도와 줘서 기쁩니다! –

3

찾을 수없는 경로는 앞에 \가 하나 있으며, UNC 공유는 두 개로 시작해야합니다. 나는 당신이 두 개의 접두사를 붙이는 것처럼 보이는 코드에서 볼 수 있지만 이월되는 것처럼 보이지는 않습니다.

작은 따옴표 대신에 큰 따옴표를 사용했지만, 그렇게하면 $ 문자도 이스케이프 할 필요가 없습니다.

file.txt라는 파일이 로컬 컴퓨터의 C : \ temp 폴더에 있다고 가정합니다.

이 실패

$computer1 = "localhost" 
Test-Path '\\$computer1\c$\temp\file.txt' 

이 작동 :

$computer1 = "localhost" 
Test-Path "\\$computer1\c$\Temp\file.txt" 
+0

첫 번째 예에서 따옴표를 수정하는 방법에 대한 답을 수정했습니다. 두 번째 예에서는 대문자 T를 제외하고 두 예제가 동일합니다.) –

+0

다시 실제로 편집하기 위해 편집했습니다. double-quotes를 필요로하는'$ computer1'이 아니라 변수를 확장해야하는'Test-Path' 문자열입니다 :-) –

+1

@Graimer OMG .... 저는 lysergic acid ...와 같습니다. 감사합니다! –

관련 문제