Powershell 修改远程计算机文件夹权限时出现拒绝访问错误

Powershell 修改远程计算机文件夹权限时出现拒绝访问错误,powershell,Powershell,正在编写代码以将权限添加到远程计算机中的特定文件夹。我们的代码与系统用户一起运行,因此在代码中,我们执行了从系统到域用户的用户上下文切换,然后从本地计算机执行命令,在远程计算机文件夹中添加域用户权限。执行代码时出现访问被拒绝错误。下面是代码供您参考 更改权限的代码(test.ps1): 执行用户上下文切换的代码: $username = "domain\username" $password = "Password" $securePassword = ConvertTo-SecureStrin

正在编写代码以将权限添加到远程计算机中的特定文件夹。我们的代码与系统用户一起运行,因此在代码中,我们执行了从系统到域用户的用户上下文切换,然后从本地计算机执行命令,在远程计算机文件夹中添加域用户权限。执行代码时出现访问被拒绝错误。下面是代码供您参考

更改权限的代码(test.ps1):

执行用户上下文切换的代码:

$username = "domain\username"
$password = "Password"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Enable-PSRemoting -Force
$session= new-pssession -ComputerName $Env:ComputerName -Credential $credential
invoke-command -Session $session -ScriptBlock {whoami}
invoke-command -Session $session -FilePath C:\Users\Desktop\test.ps1
错误:

访问被拒绝类别信息:权限被拒绝: (\remote computer\test:String)[Get ChildItem], 未经授权的访问例外 +FullyQualifiedErrorId:

ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand +PSComputerName:本地计算机


这看起来像是一个双跳问题,因为您正在模拟另一个用户,然后连接到另一台服务器上的共享-这是不允许的。即使你连接的是同一台电脑,我认为你通过远程“出去”然后“回来”,这算是一个跳跃。如果您以用户身份登录到“admin”服务器,那么您是否可以连接并管理远程共享?是的,我可以管理远程共享似乎这可能是一个模拟问题。要尝试的两个选项是,或者,然后再次模拟以转到下一个跃点。您尝试使用的用户在本地计算机[PSComputerName:local computer]上是否具有必要的权限?您可以尝试使用“以其他用户身份运行”,只需按住shift键并在powershell图标上单击鼠标右键,然后输入pwd并只运行ACL命令,查看您是否可以执行所需的操作。另一件事是策略,可能其他用户在此电脑上没有登录权限
$username = "domain\username"
$password = "Password"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Enable-PSRemoting -Force
$session= new-pssession -ComputerName $Env:ComputerName -Credential $credential
invoke-command -Session $session -ScriptBlock {whoami}
invoke-command -Session $session -FilePath C:\Users\Desktop\test.ps1