How to access a network shared drive inside Invoke-command

馋奶兔 提交于 2019-12-13 08:06:51

问题


I was using below script to copy files from network share to local drive. But,I was not able to access path and getting Path not found error. MY use case is I need to execute this script from Jenkins server and remote into server1 and then have copy files from shared directory (\server2\QlikView) which is already mounted to the server1 as S:\ drive. I was able to access this shared path from powershell If I run the command from server1.But, not inside Invoke-Command script block as shown. Any thoughts on this?

$server = "server1"
$source_dir = "\\server2\QlikView"
$processing_dir = "M:\script_test\processing"
$processed_dir = ""
$user = 'Domain\user1'
$Password = '******'
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $User, $SecurePassword

 Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {
  param ($server,$source_dir,$processing_dir)
echo "$source_dir"
 Test-path $source_dir
 copy-item -Path $source_dir\* -Destination M:\script_test
  } -ArgumentList $server,$source_dir,$processing_dir

回答1:


By default PowerShell remoting does not allow credential delegation or "second hop". If you want to connect to a remote machine (in this case a network share) from a remoting session, you need to allow the credentials to be delegated to that machine. To allow it you need to configure CredSSP. Take a look here for details on the problems as well as how to set it up: https://blogs.technet.microsoft.com/heyscriptingguy/2012/11/14/enable-powershell-second-hop-functionality-with-credssp/



来源:https://stackoverflow.com/questions/47316715/how-to-access-a-network-shared-drive-inside-invoke-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!