locked
Modifying registry value fails on remote servers RRS feed

  • Question

  • Hi,

    I'd like to modify a registry key in some Windosw Servers in an Active Directory domain which are listed in a text file.

    I run following PowerShell script on a Domain Controller as domain admin, but I got always "failure":

    $Computers = Get-Content "D:\WindowsAgents.txt"
    $Path = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlsSet\Services\HealthService\Parameters\Management Groups\CentralMonitoring"
    $Property = "maximumQueueSizeKb"
    $Value = "76800"
    
    $results = foreach ($computer in $Computers)
    {
        If (test-connection -ComputerName $computer -Count 1 -Quiet)
        {
            Try {
                Set-ItemProperty -Path $path -Name $Property -Value $Value -ErrorAction 'Stop'
                $status = "Success"
            } Catch {
                $status = "Failed"
            }
        }
        else
        {   
            $status = "Unreachable"
        }
        
        New-Object -TypeName PSObject -Property @{
            'Computer'=$computer
            'Status'=$status
        }
    }
    
    $results |
    Export-Csv -NoTypeInformation -Path "D:\out.csv"
    

    I am very new in Powershell. Can somebody help me how can I correct this issue, or give any other script which can work well?

    Best Regards

    Birdal

    Tuesday, March 13, 2018 8:46 AM

All replies

  • You are checking if the server is reachable but you are not reaching it. If you want to execute a command on a remote machine you have to use either a cmdlet what supports remoting by itself with the parameter -ComputerName or you have to use Invoke-Command.

    So in your script you're trying to write to the local regsitry of the server you're running the script on again and again and again ...  ;-)


    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Tuesday, March 13, 2018 9:54 AM
    • Proposed as answer by psott Tuesday, March 13, 2018 10:03 AM
    Tuesday, March 13, 2018 9:53 AM
  • Hi,

    OK, I will try Invoke-Command.

    No, this script tries to modify registry value on the servers, which are listed in the file "D:\WindowsAgents.txt". Or not?

    Best Regards

    Birdal

    Tuesday, March 13, 2018 11:22 AM
  • No, this script tries to modify registry value on the servers, which are listed in the file "D:\WindowsAgents.txt". Or not?

    No - not at the moment. That's what I meant. You have a loop iterating over your server list but the cmdlet Set-ItemProperty runs localy on your server.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, March 13, 2018 11:27 AM