클라이언트와 서버가 있습니다. 클라이언트는 같은 스크립트를 호출합니다 :Powershell Server 네트워크 드라이브
cmd.exe /C copy "\\server\file1.pdf" "\\server2\file1.pdf"
어떻게 수행하십시오 jclbuild2.bat
실행하고 \\otherserver\something
같은 네트워크 드라이브에 액세스 할 서버에
#Predefine necessary information
$Username = "Niels"
$Password = "password"
$ComputerName = "192.168.1.51"
$Script = {powershell c:/build/jclbuild2.bat}
#Create credential object
$SecurePassWord = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username, $SecurePassWord
#Create session object with this
$Session = New-PSSession -ComputerName $ComputerName -credential $Cred
#Invoke-Command
$Job = Invoke-Command -Session $Session -Scriptblock $Script
echo $Job
#Close Session
Remove-PSSession -Session $Session
를, 내가이 명령을 수행 할 경우 액세스가 거부 말한다 원격 서버의 powershell 파일에서 네트워크 드라이브에 액세스합니까? $ username 및 $ password와 함께 사용하는 사용자는 네트워크 드라이브에 액세스 할 수 있어야합니다.
저는 이중 홉 문제라고 생각합니다. 해결 방법을 모르겠습니다.
일부 WSMAN 오류가 발생합니다. targetcomputer의 ID는 WSMAN-servce로 확인할 수 없습니다. – Niels
@Niels 어떤 명령이 실패 했습니까? 추가 정보는 [this] (http://dustinhatch.tumblr.com/post/24589312635/enable-powershell-remoting-with-credssp-using-group)를 참조하십시오. 내가 이것을 설정할 때 FQDN과 논쟁이 많이 일어나는 것을 기억합니다. 세션을 만들 때 FQDN을 사용해야 할 수도 있습니다. –
나는 그것을 고쳤다. 나는'-Authentication'을 추가 할 때 이상한 오류를 겪었고 스크립트를 간소화 시켰습니다. 감사 ! – Niels