我正在尝试使用invoke-command编写一个非常简单的脚本来编辑已存在的注册表项。我的问题是,当我运行脚本时没有错误,并且它返回成功但未在远程计算机上进行更改。
$Path = "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl\"
$Name = "CrashDumpEnabled"
$Value = "1"
$RComputers = Get-Content "C:\temp\computerlist.txt"
ForEach ($Computer in $Rcomputers)
{
If (test-connection -ComputerName $computer -Count 1 -Quiet)
{
$Results = Invoke-Command $Computer -ScriptBlock {
Try
{
Param($Path,$Name,$Value) Set-ItemProperty -path $path -Name $Name -Value $Value -ErrorAction 'Stop' -ArgumentList $Path,$Property,$Name
}
Catch
{
$status = "Failed"
}
Finally
{
$status = "Success"
}}}
else{
$status = "Unreachable"
}}
New-Object -TypeName PSObject -Property @{
'Computer' = $computer
'Status' = $status}
$results | Out-File "C:\temp\Registry Report.txt"