我正在从远程计算机触发以下脚本,以将执行者IP(192.168.4.231)添加到受信任列表中。但以下脚本被解雇了,但并非没有得到预期的结果。
请让我知道我在脚本下执行任何错误的方法。
$servers = @("192.168.4.236")
foreach($server in $servers) {
$username = 'administrator'
$password = '*******'
$pw = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $pw)
$s = New-PSSession -ComputerName $server -Credential $cred
Enter-PSSession $s
Invoke-Command -Session $s -Scriptblock {
Invoke-Expression 'winrm set winrm/config/client '@{TrustedHosts="192.168.4.231"}''
}
Write-Host "Completed"
Remove-PSSession $s
}