0

I am trying to write a pretty simple script using the invoke-command to edit a registry key that already exist. My issue that there are no errors when I run the script and it returns as a success but the change isn't made on the remote computer.

$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"
  • 1
    http://stackoverflow.com/questions/12600921/handle-errors-in-scriptblock-in-invoke-command-cmdlet you should put try catch inside scriptblock – 4c74356b41 Feb 24 '17 at 14:37
  • Your else statement looks to be in the wrong place also. It doesn't have }{ around it. – Mark Wragg Feb 24 '17 at 14:42
  • I corrected my {} but the script doesn't make the changes remotely and still returns a success, I am guessing because there is no detected error even though the action wasn't completed? – Howard McNitt Feb 24 '17 at 15:49

0 Answers0