【问题标题】:Invoke-command localhost Access Denied调用命令 localhost 访问被拒绝
【发布时间】:2020-02-23 22:25:25
【问题描述】:

当尝试对本地主机调用命令时,我被拒绝访问。

我已确认 PS 远程处理已启用且帐户为管理员。此外,从远程机器远程处理也可以正常工作。

Invoke-Command -computername LocalHost -scriptblock {hostname} 

我希望返回本地计算机的主机名,但我收到拒绝访问错误。

【问题讨论】:

  • 如果您启用了 UAC,您必须在 localhost 的提升提示下。

标签: powershell powershell-remoting invoke-command


【解决方案1】:

使 PSRemoting 服务自动启动

在主机和远程机器上

Set-Service winrm -StartupType Automatic 
Start-Service winrm

启用 PSREmoting

在主机和远程机器上

EnablePSRemoting -Force

将计算机添加到受信任的主机

在远程机器上

Set-Item wsman:\localhost\Client\TrustedHosts -Value "$(hostname),*$((Get-WmiObject Win32_ComputerSystem).Domain)"

在 Powershell 远程处理中启用多跳

确定哪些主机允许传递 Creds

Enable-WSManCredSSP –Role Client –DelegateComputer   "$(hostname),*$((Get-WmiObject Win32_ComputerSystem).Domain)"

在源机器上。

Enable-WSManCredSSP –Role Server

您必须指定身份验证和凭据

在主机上

$Cred = [System.Management.Automation.PSCredential]::new("<username>",$("<Password>" | ConvertTo-SecureString -AsPlainText -Force))
invoke-command -ComputerName localhost -ScriptBlock {Write-Host $args[0]} -ArgumentList "Hello!, It Works" -Authentication Credssp -Credential $cred

参考

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_troubleshooting?view=powershell-6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 2021-07-31
    • 2013-07-28
    • 2023-03-20
    相关资源
    最近更新 更多