Powershell 将注册表项添加到多台远程计算机
我想在多台机器上创建一个新的注册表项,但我的脚本无法工作。你能给我一些提示吗Powershell 将注册表项添加到多台远程计算机,powershell,Powershell,我想在多台机器上创建一个新的注册表项,但我的脚本无法工作。你能给我一些提示吗 Import-Module ActiveDirectory Add-Type -AssemblyName System.Web $Computers = Get-Content -Path 'G:\Shares\xxx\SebaTesty\computerlist.txt' $results = foreach ($computer in $Computers) { If (test-connection
Import-Module ActiveDirectory
Add-Type -AssemblyName System.Web
$Computers = Get-Content -Path 'G:\Shares\xxx\SebaTesty\computerlist.txt'
$results = foreach ($computer in $Computers)
{
If (test-connection -ComputerName $computer -Count 1 -Quiet)
{
Try
{
New-ItemProperty -Path "hklm:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name "ArpRetryCount" -Value 0 -PropertyType "DWord"
$status = "Success"
}
Catch
{
$status = "Failed"
}
}
}
Read-Host -Prompt "wait for enter"
使用
-ComputerName
参数查看cmdlet。谢谢大家。这项工作正在进行中
Import-Module ActiveDirectory
Add-Type -AssemblyName System.Web
$Computers = Get-Content -Path 'G:\Shares\xxx\SebaTesty\computerlist.txt'
$results = foreach ($computer in $Computers) {
If (test-connection -ComputerName $computer -Count 1 -Quiet) {
Try {
Invoke-Command -ComputerName $Computers -ScriptBlock {
New-ItemProperty -Path "hklm:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name "ArpRetryCount" -Value 0 -PropertyType "DWord"
}
$status = "Success"
}
Catch {
$status = "Failed"
}
}
}
Read-Host -Prompt "wait for enter"
Microsoft scripting guy有一个博客,介绍了您想要做的事情:@JamesC。和@Martin Brandl提供了一些很好的链接。一个疑难解答提示:您正在循环查看列表
$Computers
,但是New ItemProperty
命令未使用变量$computer
。PowerShell将只在本地PC上执行该命令,它将为计算机中的每个$computer
执行一次