将注册表项添加到多台远程计算机



我想在多台计算机上创建一个新的注册表项,但我的脚本不起作用。你能给我一些提示吗?

Import-Module ActiveDirectory
Add-Type -AssemblyName System.Web 
$Computers = Get-Content -Path 'G:SharesxxxSebaTestycomputerlist.txt'
$results = foreach ($computer in $Computers)
{
    If (test-connection -ComputerName $computer -Count 1 -Quiet)
    {
        Try
        {
            New-ItemProperty -Path "hklm:SYSTEMCurrentControlSetServicesTcpipParameters" -Name "ArpRetryCount" -Value 0 -PropertyType "DWord"
            $status = "Success"
        }
        Catch
        {
            $status = "Failed"
        }
    }
}
Read-Host -Prompt "wait for enter"

使用 -ComputerName 参数查看Invoke-Command cmdlet。

谢谢大家。这现在有效。

Import-Module ActiveDirectory
Add-Type -AssemblyName System.Web 
$Computers = Get-Content -Path 'G:SharesxxxSebaTestycomputerlist.txt'
$results = foreach ($computer in $Computers) {
    If (test-connection -ComputerName $computer -Count 1 -Quiet) {
        Try {
            Invoke-Command -ComputerName $Computers -ScriptBlock {
                New-ItemProperty -Path "hklm:SYSTEMCurrentControlSetServicesTcpipParameters" -Name "ArpRetryCount" -Value 0 -PropertyType "DWord"
            }
            $status = "Success"
        }
        Catch {
            $status = "Failed"
        }
    }
}
Read-Host -Prompt "wait for enter"

最新更新