PowerShell: Add and Remove a Registry Key

How to Add a Registry Key

# Add New Registry Key
Set-ItemProperty -Path $regHive -Name $keyname -value $value

# Validation
Get-ItemProperty $regHive -name $keyname

PS C:\Users\backupadmin> Get-ItemProperty $regHive -name $keyname
OleDbTimeout : 600
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft
PSChildName  : MSCRM
PSProvider   : Microsoft.PowerShell.Core\Registry

How to Remove a Registry Key

# Remove Registry Key
Remove-ItemProperty -Path $regHive -Name $keyname -value $value

Leave a Reply

Your email address will not be published. Required fields are marked *