How can I use PowerShell to make remote registry changes?

后端 未结 3 1384
梦如初夏
梦如初夏 2020-12-21 13:27

I have tested the following PowerShell registry settings and it sets them correctly. Could someone show me the way to do this for a remote computer?

New-Item         


        
相关标签:
3条回答
  • 2020-12-21 13:43

    You might want to check the PSRemoteRegistry PowerShell Module, and its version for PowerShell 3.0 (with x86.x64 support, http://psrr.codeplex.com/).

    0 讨论(0)
  • 2020-12-21 14:02

    Use this as example:

    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computername ) 
            $regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",$true) 
            $regKey.SetValue("New_Valuename_String","New_Valuedata",[Microsoft.Win32.RegistryValueKind]::String) 
    

    To create a new key you need use powershell remoting with invoke-command for new-item cmdlet.

    0 讨论(0)
  • 2020-12-21 14:05

    If you just want to delete a key

    $exchangeServers = @("xxxxx");
    $hive = [Microsoft.Win32.RegistryHive]::LocalMachine;
    $key = "SYSTEM\CurrentControlSet\Control\Lsa";
    
    foreach ($exchangeServer in $exchangeServers)
    {
        $regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hive, $exchangeServer.ToString());
        $regKeys = $regBaseKey.OpenSubKey($key,$true);
        $beforeVal = $regKeys.GetValue("DisableLoopbackCheck");
        Write-Host $exchangeServer " - " $beforeVal;
        $regKeys.DeleteValue("DisableLoopbackCheck"); # a try catch can be placed here if there is a concern the key won't exist
        $keyNames = $regKeys.GetSubKeyNames();
        $afterVal = $regKeys.GetValue("DisableLoopbackCheck");
        if ($afterVal -eq $null)
        {
            Write-Host $exchangeServer " - deleted" -ForegroundColor DarkGreen;
        }
        else
        {
            Write-Host $exchangeServer " - " $afterVal -ForegroundColor Red;
        }
        Write-Host " ";
    }
    
    0 讨论(0)
提交回复
热议问题