locked
Powershell script to update a specific registry key RRS feed

  • Question

  • I was trying to use this powershell script to update a specific registry key.

    $Computers = Get-Content "C:\temp\VBS\Servername.txt"
    $Path = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion"
    $Property = "RegisteredOrganization"
    $Value = "Updated Value Test"

    $results = foreach ($computer in $Computers)
    {
       Set-ItemProperty -Path $path -Name $Property -Value $Value -ErrorAction 'Stop'         
    }

    But I seem to be getting the below error :

    Requested registry access is not allowed.
    At line:8 char:20

    But I went to regedit and checked the permission of the key by right clicking and I seem to be having full access ( I have administrator rights on the server).

    I am not sure what could be the issue. Can anyone please help with some ideas?

    Thanks

    • Moved by Bill_Stewart Thursday, January 25, 2018 10:10 PM User should not be doing this
    Thursday, November 9, 2017 11:29 AM

All replies

  • Run your console(powershell) in elevated mode(as administrator) to achieve this

    (66,65,83,65,84,73|%{[char]$_})-join''

    Thursday, November 9, 2017 11:39 AM