2009-09-03 4 views
3

로컬 컴퓨터에 AD 통해 관리자 권한이 원격 컴퓨터에서 파일을 복사하려면 PowerShell 얻으려고합니다. 가장 이상한 곳에서 실패합니다.PowerShell : 복사 항목 경로를 찾을 수 없습니다

$configs = Get-ChildItem -Recurse -ErrorAction SilentlyContinue -Filter "*.config" $serverUNCPath 
foreach($config in $configs){ 
    $config_target_dir = $dest.Path + $config.Directory.FullName.Replace($serverUNCPath,"") 
    if(Test-Path -Path $config_target_dir){ 
     Copy-Item $config -Destination $config_target_dir 
    } 
} 

그것은 메시지

Cannot find path 'D:\ServerDeploy\TestMachine1\website\web.config' because it does not exist. 
At :line:39 char:12 
+   Copy-Item <<<< $config -Destination $config_target_dir 

D:\ServerDeploy\TestMachine1\website이 존재하는 경로 실패 : 다음 스크립트의 조각입니다. 나는 이걸보고 화를 낼거야.

문제를 해결하려면 어떻게해야합니까?

답변

7

eeeeh .... 괜찮습니까? 나는 갑자기 마술 일

Copy-Item $config.FullName $config_target_dir 

으로 라인

Copy-Item $config -Destination $config_target_dir 

를 교체 한 경우

.... 어떻게 제공

?

+6

PS에서 실제 개체를 다루고 있다는 것을 잊지 마십시오. 일반적으로 cmdlet에 개체를 전달할 때 cmdlet은 작업 할 올바른 속성을 선택하는 것이 좋습니다. 이 경우 System.IO.FileSystemInfo.FileInfo 개체를 Copy-Item cmdlet에 전달할 것입니다. cmdlet은 기본적으로 .Name 속성을 사용하고 있으며 복사본이 작동하기에 충분한 정보가 아니라고 생각합니다. .FullName 속성을 cmdlet에 명시 적으로 지정하면 이제는 필요한 정보가 제공됩니다. – EBGreen

+0

흠, 그것은 오류를 설명 할 것이지만, 진절머리 나는 오류 메시지는 아닙니다. 대상 위치가 존재하지 않는다는 오류로보고하는 이유는 무엇입니까? – AndreasKnudsen

+0

Copy-Item이 실행될 때의 현재 작업 디렉토리는 무엇입니까? 내 생각 엔 D : \ ServerDeploy \ TestMachine1 \ website입니다. EBGreen과 마찬가지로, Copy는 $ config를 상대 경로로 취급합니다. 따라서, (join-path (pwd) $ config.Name) *는 전체 소스 위치라고 생각합니다. –