Как запустить сценарий powershell в качестве пользователя домена? - PullRequest
0 голосов
/ 12 октября 2018

У меня есть блок скрипта, который я пытаюсь запустить как пользователя другого домена.

$Username = 'domain\test'
$Password = '1234'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName,$pass

Invoke-Command -ScriptBlock{
write-host "hello"

} -Credential $cred -ComputerName $env:COMPUTERNAME

При запуске я получаю следующую ошибку:

[test-pc] Connecting to remote server test-pc failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests.
 Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM se
rvice: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.

Почему скрипт пытается аутентифицироваться локально, а не против DC?Спасибо

1 Ответ

0 голосов
/ 12 октября 2018

Если вы на самом деле не хотите запускать скрипт удаленно, вы можете использовать Start-Process для запуска Powershell от имени другого пользователя, который затем выполнит вашу команду / скрипт от имени этого пользователя.

(см. справку по командной строке powershell для получения подробных параметров и примеров синтаксиса)

# Using Get-Credential to illustrate, substitute with your own credential code
$cred = Get-Credential

# Run Command:
Start-Process -FilePath Powershell -Credential $cred -ArgumentList '-Command', 'Write-Host "Hello"'

# Run Script:    
Start-Process -FilePath Powershell -Credential $cred -ArgumentList '-File', 'C:\folder\script.ps1'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...