powershell removing a specific registry key - powershell

I am new to PowerShell and I am trying to remove a specific value from the run registry key. I am using the remove-item command, however, I don't see a switch to specify a single value. I don't want to remove the entire key, just one value.
For reference the batch equivalent of what I am trying to do:
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v SunJavaUpdateSched /f

Remove-ItemProperty -Name 'nameofkeyentry' -Path 'pathtothekey'
For example the key 'HKCU:\Accessibility\AudioDescription' has 3 values
(Default) REG_SZ (value not set)
Locale REG_SZ [blank]
On REG_SZ 0
Suppose we would like to remove the 3rd value 'On' - we would do so as follows
Remove-ItemProperty -Name 'On' -Path 'HKCU:\Accessibility\AudioDescription'
note HKCU stands for HKEY_CURRENT_USER, each root is abbreviated intuitively the same way (e.g. HKEY_CLASSES_ROOT = HKCR:\, etc)

use the cmdlet remove-itemproperty

Related

How to add to a windows registry value containing double quotes using robot framework?

I want to add a windows registry key at path HKLM:\SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls with key name as 1 and value as {"pattern":"[*.]","filter":{}}. Upon running below command, double quotes are getting trimmed in the added entry.
${rc} ${out}= OperatingSystem.Run And Return Rc And Output powershell Start-Process -Verb runAs -Wait powershell -ArgumentList "{ New-ItemProperty -path HKLM:\\SOFTWARE\\Policies\\Google\\Chrome\\AutoSelectCertificateForUrls -Name 1 -Value '{\"pattern\":\"[*.]\",\"filter\":{}}' -PropertyType \"String\" -Force }"
Registry Key after command
It runs successfully but removes the double quotes in the Registry key.
Expectation in Registry : {"pattern":"[*.]","filter":{}}
Observed value in Registry : {pattern:[*.],filter:{}}
As observed above, it is removing double quotes surrounding 'pattern' and 'filter' words in the expression. Need help to successfully insert double quotes in registry key.

How would I need to change my code to fit into the HKEY_USERS format instead of HKCU?

We are upgrading our Software to its 2019 version. Apparently it is a
bugger, so it has been suggested to do a clean install including deleting
some registry keys from previous versions.
We also want to save the autologins of our users so they don't need to
reset them up and we can also do something similar with new deployments.
I got some code working for what we want to do, but the problem is that
when I went to add it to our uninstall script, the uninstall script has
some different paths using HKEY_USERS vs my HKCU.
How can I modify my code to fit into our uninstall script which is using
HKEY_USERS?
Haven't tried anything other than the original code yet. Not sure where
to begin. This is my 1st attempt using powershell (or any coding really).
#Basically this is supposed to grab the users autologin key, save it,
#then after nuking the reg, put it back
$path = 'HKCU:\Software\SolidWorks\Applications\PDMWorks
Enterprise\ServerConfig\FakeVaultName'
$autologinkey = "HKCU\Software\SolidWorks\Applications\PDMWorks
Enterprise\ServerConfig\FakeVaultName"
$user=(Get-ItemProperty -Path $path -Name User).user.ToLower()
#/y forces overwriting the existing file without prompt.
if($user -ne 'fakeusername' -and $user){
reg export $autologinkey "$env:TEMP\fakekeyname.reg" /y
}
#These next steps need to be done after the uninstall/reg scrubbing
if($user -ne 'fakeusername' -and $user){
reg.exe import "$env:TEMP\fakekeyname.reg"
}
#I think this could maybe get away with just the else part instead of
#elseif + the user?
elseif($user -eq 'fakeusername' -or !$user){
reg.exe import
"\\fakecompanyname.com\Files\Public\IT\Protected\Projects\SOLIDWORKS
2019
deployment\Vault fakeusername auto login keys.reg"
}
#I need to make my code work with the following that loops through
#all the different users on the machine (not the whole code, just the
#HKEY_USERS part that I'm concerned with
# This is where you can read/modify a users portion of the registry
$unwantedDirectories += "registry::HKEY_USERS\
{0}\Software\SolidWorks" -f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\SRAC" -f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\eDrawings"
-f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\SOLIDWORKS
2017" -f $($Item.SID)
I don't know where to begin. My code works, but not sure how to tie it in
with the other HKEY_USERS part.
Please advise.
Edit: 7/9/2019
The script is kind of working, but it will import the reg key to the logged in user vs. the profile we want it to. Below is current working (mostly) code.
###############################################################################
#This part is ran before the reg nuke.
$autologinpath = registry::HKEY_USERS\0}\Software\SolidWorks\Applications\PDMWorks Enterprise\ServerConfig\FakeVaultName' -f $($Item)
$autologinkey = "HKU\{0}\Software\SolidWorks\Applications\PDMWorks Enterprise\ServerConfig\FakeVaultName" -f $($Item)
$autologinuser=(Get-ItemProperty -Path $autologinpath -Name User).user.ToLower()
if($autologinuser -ne 'fakeusername' -and $autologinuser){
reg export $autologinkey "$env:TEMP\fakekeyname.reg" /y
}
###############################################################################
#This part is ran after the reg nuke.
if($user -ne 'fakeusername' -and $autologinuser){
reg.exe import "$env:TEMP\fakekeyname.reg"
}
else {
reg.exe import "\\fakecompanyname.com\Files\Public\IT\Protected\Projects\SOLIDWORKS 2019 deployment\Vault fakeusername auto login keys.reg"
}
Edit: 7/9/2019 2:09pm
Thanks for the help! I think we got it. We ended up doing a manual add of the reg key values. Probably not very elegant, but seems to be working.
Else {
reg add $autologinkey /v "SettingsFromServer" /t REG_DWORD /f /d #
reg add $autologinkey /v "User" /t REG_SZ /f /d fakeusername
reg add $autologinkey /v "Config" /t REG_BINARY /f /d blahblahblahinfinity..
reg add $autologinkey /v "CacheW" /t REG_DWORD /f /d #
reg add $autologinkey /v "SinglePointLogin" /t REG_DWORD /f /d #
}

Is there an easier way to check for values in a registry path then delete all values im looking for?

So Im running power shell script where it tests the path of a registry value and if it exists it will be deleted. Question if there are more values within the registry key whats a simpler way of detecting and deleting them all? I dont want to repeat the same script for every single value.
$registrypath=("HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" , "DeferFeatureUpdatesPeriodInDays" )
if (Test-Path $registrypath)
{
cmd /c reg delete HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings /v DeferFeatureUpdatesPeriodInDays /f
}
To remove all Properties and their values from a registry key , without removing Sub Keys and the key itself You just need to run :
Remove-ItemProperty -Path $path -Name *

Changing a binary registry value with PowerShell from a .reg file

I have exported a registry directory that I would like to use in a PowerShell script. The .reg file contains two very long hex strings that I have been trying to use in Set-ItemProperty and New-ItemProperty, but neither have been successful. I keep getting errors whenever I run my script because PowerShell seems to have problems with the 'cc' hex values.
Things I have tried:
Assigning the hex values to a variable and using that in Set-ItemProperty and New-ItemProperty
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "Favorites" -PropertyType BINARY -Value $favorites
Putting the hex values directly into the cmdlet with no formatting
Putting the hex value into the cmdlet with double and single quotes around them
Removing the old keys and creating new ones with-PropertyType Binary
Reg file: https://pastebin.com/rrAzMivQ
PS script: https://pastebin.com/NrQFr71w
Solved
I was able to get my script to work. Here is the final result if anyone is interested: https://pastebin.com/PW5Cjy0d
"The code is very long. Follow link."

Unlock the reading pane in outlook 2016

How do you write a script to change a registry key? What I am trying to do is have a script I can run to unlock the reading pane in outlook 2016.
The path of the registry key is:
Computer\HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\options
disablereadingpane REG_DWORD 0x00000001 (1)
And I need to change the 1 to a 0. In the 0x00000001
Any help getting started with this would be greatly appreciated.
My comment was faulty it's add not edit.
reg.exe is the command line registry manipulation tool. See reg.exe /?
You may first check if the key exists and what value / data it has.
Reg Query "HKCU\Software\Policies\Microsoft\office\16.0\outlook\options"
To adda key/value/data pair
Reg add "HKCU\Software\Policies\Microsoft\office\16.0\outlook\options" /v disablereadingpane /t REG_DWORD /d 0x0
optionally you may add a /f force option to overwrte current content.
I think you're looking for something like this, if you're using powershell. It's pretty self explanatory
Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\office\16.0\outlook\options -Name disablereadingpane -Value 0