Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何在Invoke命令中访问网络共享驱动器_Powershell_Powershell 2.0 - Fatal编程技术网

Powershell 如何在Invoke命令中访问网络共享驱动器

Powershell 如何在Invoke命令中访问网络共享驱动器,powershell,powershell-2.0,Powershell,Powershell 2.0,我使用下面的脚本将文件从网络共享复制到本地驱动器。但是,我无法访问路径,并且获取路径未找到错误。我的使用案例是,我需要从Jenkins服务器执行此脚本,并将其远程执行到server1,然后从共享目录(\server2\QlikView)复制文件,该目录已作为S:\drive装载到server1。如果我从server1运行命令,我可以从powershell访问此共享路径。但是,在调用命令脚本块内,如图所示,无法访问。有什么想法吗 $server = "server1" $source_dir =

我使用下面的脚本将文件从网络共享复制到本地驱动器。但是,我无法访问路径,并且获取路径未找到错误。我的使用案例是,我需要从Jenkins服务器执行此脚本,并将其远程执行到server1,然后从共享目录(\server2\QlikView)复制文件,该目录已作为S:\drive装载到server1。如果我从server1运行命令,我可以从powershell访问此共享路径。但是,在调用命令脚本块内,如图所示,无法访问。有什么想法吗

$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

默认情况下,PowerShell远程处理不允许凭据委派或“第二跳”。如果要从远程处理会话连接到远程计算机(在本例中为网络共享),则需要允许将凭据委派给该计算机。要允许它,您需要配置CredSSP。请在此处查看有关问题以及如何设置的详细信息:

为什么您认为映射的网络驱动器(
M
)在远程计算机上以相同的方式映射(例如根UNC路径)?感谢您的回复。我通过使用Net Use/user:$user//server1/dir1$Password解决了此问题。“CredSSP仅在Windows Vista和Windows Server 2008上可用。”