Powershell script
Необходимо поправить/написать скрипт чтобы он мог коннектится с Linux на Windows и удаленно выполнять команду.
Src host Linux , centos7: powershell-7.0.3-1.rhel.7.x86_64
Dst host Win , server 20016
Скрипт:
$WindowsUserName = 'local\amazonadmin'
$WindowsPassword = 'amazon'
$address = '8.8.8.8'
$windowsCredentialPassword = ConvertTo-SecureString -asPlainText -Force -String $WindowsPassword
$windowsCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($WindowsUserName, $windowsCredentialPassword)
$psSession = New-PSSession -ComputerName $address -Credential $windowsCredential
Invoke-Command -Session $psSession {
Write-Host (Get-ChildItem C:\).Name
}
Ошибка:
pwsh
PowerShell 7.0.3
Copyright (c) Microsoft Corporation. All rights reserved.
Type 'help' to get help.
PS /root> ./ps.ps1
New-PSSession: /root/ps.ps1:8
Line |
8 | … psSession = New-PSSession -ComputerName $address -Credential $windows …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| MI_RESULT_ACCESS_DENIED
Invoke-Command: /root/ps.ps1:10
Line |
10 | Invoke-Command -Session $psSession {
| ~~~~~~~~~~
| Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.