Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, June 14, 2012 5:32 PM
Hello,
I'm fairly new to powershell and I want to change a registry value.
Ideally, this is what it would do...
1. Check the value of the key hklm:software\microsoft\windows\currentversion\policies\system -name enablelua
2. if the value is 0, do nothing
3. if the value is not 0, set it to 0
Can anyone help me out with this?
Thanks,
Scott
All replies (8)
Thursday, June 14, 2012 5:49 PM ✅Answered | 5 votes
Hi Scott,
Check Get-ItemProperty and Set-ItemProperty
$val = Get-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name "EnableLUA"
if($val.EnableLUA -ne 0)
{
set-itemproperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name "EnableLUA" -value 0
}
Thursday, June 14, 2012 5:49 PM ✅Answered | 1 vote
$value =(Get-Itemproperty hklm:software\microsoft\windows\currentversion\policies\system).enablelua
If ($value -ne 0){
Set-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name enablelua -Value 0
}
Give that a try
Thursday, June 14, 2012 5:51 PM ✅Answered
Try this:
if ((Get-ItemProperty 'hklm:software\microsoft\windows\currentversion\policies\system' -name enablelua | select -exp enablelua) -ne 0) {
Set-ItemProperty 'hklm:software\microsoft\windows\currentversion\policies\system' -Name enablelua -Value 0 }
Grant Ward, a.k.a. Bigteddy
Thursday, June 14, 2012 5:55 PM
$value =(Get-Itemproperty hklm:software\microsoft\windows\currentversion\policies\system).enablelua If ($value -neq 0){ Set-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name enablelua -Value 0 }
Give that a try
That -neq should be -ne, no?
Grant Ward, a.k.a. Bigteddy
Thursday, June 14, 2012 5:56 PM
Hi Scott,
Check Get-ItemProperty and Set-ItemProperty$val = Get-ItemProperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name "EnableLUA" if($val -ne 0) { set-itemproperty -Path hklm:software\microsoft\windows\currentversion\policies\system -Name "EnableLUA" -value 0 }
I don't think this will work, because you need to select out the value of the particular property. Try it and check the value of $val.
Grant Ward, a.k.a. Bigteddy
Thursday, June 14, 2012 6:01 PM
yes it should be -ne instead of -neq
I am not at a machine I can test, but it should work, as I used that in a previous post, just a slight modification.
Thursday, June 14, 2012 6:58 PM
Thanks everybody. Very helpful!
Thursday, March 6, 2014 2:02 AM
Here is the blog post that you can use
http://msexchange.me/2014/01/02/readwrite-registry-for-multiple-servers-via-powershell-part1/
http://msexchange.me/2014/01/04/readwrite-registry-for-multiple-servers-via-powershell-part2/
Sukhija Vikas