0
我只是想學習PowerShell,並通過一些例子,我發現想出了以下腳本。我試圖在不同的服務器上註冊一些環境變量。當我運行它時,出現錯誤 -在PowerShell中的遠程計算機上註冊環境變量
Invoke-Command : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\Users\gswartz\Desktop\regvalue.ps1:3 char:16
+ Invoke-Command <<<< -ComputerName $server [Environment]::SetEnvironmentVariable("xxxx", "xxxx", "Machine")
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand
這是腳本。有人能告訴我我做錯了什麼嗎?
function set_vars($server) {
Invoke-Command -ComputerName $server [Environment]::SetEnvironmentVariable("xxxx", "xxxx", "Machine")
Invoke-Command -ComputerName $server [Environment]::SetEnvironmentVariable("xxxx", "xxxx", "Machine")
Invoke-Command -ComputerName $server [Environment]::SetEnvironmentVariable("xxxx", "xxxx", "Machine")
Invoke-Command -ComputerName $server [Environment]::SetEnvironmentVariable("xxxx", "xxxx", "Machine")
Write-Host "vars set for $server"
}
$servers = @("server1","server2")
$servers | ForEach{
set_vars $_
}
'{'和'}'失蹤。 – PetSerAl
建議使用組策略來執行此操作而不是腳本。 –