调用命令无法复制共享网络文件夹?

问题描述 投票:0回答:1

我一直在开发一个脚本,可以从我们的服务器中删除旧版本的 zabbix,并安装最新版本。

当我使用调用命令时,从共享文件夹复制文件时遇到问题。

我可以直接从目标机器运行这个脚本,并且我可以完美地复制文件夹:

$Installer = '\\Server01\Zabbix'
Write-Host -f green "[INFO]: Attempting to copy the folder located on $installer." 
 
 
 try{
 Copy-Item -Path  $installer -Destination c:\ -recurse -force
 Write-Host -f green "[INFO]: $installer is succesfully copied on C:\Zabbix on $env:computername." }
 catch
 {write-host -f red "[ERROR]: Copying $installer encountered an error on $env:computername : $error"
 $error.clear()}

由于我将在多个服务器上运行它,所以我选择了以下方法:

Invoke-Command -ComputerName $server -ScriptBlock{}

这是示例代码:

$servers = @( 'Server02')

foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock {

 $Installer = '\\Server01\Zabbix'
Write-Host -f green "[INFO]: Attempting to copy the folder located on $installer." 
 
 try{
 Copy-Item -Path  $installer -Destination c:\ -recurse -force
 Write-Host -f green "[INFO]: $installer is succesfully copied on C:\Zabbix on $env:computername." }
 catch
 {write-host -f red "[ERROR]: Copying $installer encountered an error on $env:computername : $error"
 $error.clear()}

}}

下面是错误消息:

[INFO]: Attempting to copy the folder located on \\Server01\Zabbix.
Access is denied
    + CategoryInfo          : PermissionDenied: (\\Server01\Zabbix:String) [Copy-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
    + PSComputerName        : Server02
Cannot find path '\\Server01\Zabbix' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (\\Server01\Zabbix:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
    + PSComputerName        : Server02

直接访问服务器 02 并运行命令而无需调用命令时,我使用相同的帐户。访问应该没问题。

有人可以帮忙吗?

谢谢!

powershell invoke-command
1个回答
0
投票

PowerShell 不支持

second-hop
开箱即用。

即您使用

Server1
上的凭据远程调用该命令。
Server1
依次尝试访问
Server2
上的资源时,它无法访问您的凭据,因为您通常不会将它们转发以供进一步使用。

在这种情况下,您需要允许

Server1
的计算机帐户的凭据访问
Server2
,或者使用允许传递您的凭据或允许帐户委派的方法。

请参阅 MS Learn - 在 PowerShell 远程处理中进行第二步

CredSSP
曾经是首选选项,但 MS 对使用 CredSSP 施加了一些进一步的限制,这可能会导致它失败。

因此,如果您无法访问 AD 中的

JEA
,我会选择使用
Kerberos delegation
(Just Enough Administration)。

© www.soinside.com 2019 - 2024. All rights reserved.