Powershell - Check for reg key if exist exit if not add RRS feed

  • Question

  • I am attempting to do the following

    1. Check to see if registry value exits
    2. If it does, exit
    3. If it does, modify and exit

    I'm relatively new to PowerShell and am in need of assistance please.

    $registryPath = 'HKLM:\SOFTWARE\WOW6432Node\Application\Application Client' $name = "ServerName" $value = "" if (!(Test-Path -Path $registryPath)) {

    [Void] (New-Item -Path $registryPath -Force) [Void] (New-ItemProperty -Path $registryPath -Name $name -PropertyType "String" -Value $value -Force) }


    • Edited by DRHeinz Monday, April 15, 2019 9:36 PM
    Monday, April 15, 2019 9:29 PM

All replies

  • You fail to tell us the issue.  What is not happening or what is your error?

    This is really all you need to do.

    $registryPath = 'HKLM:\SOFTWARE\WOW6432Node\Application\Application Client'
    $name = 'ServerName'
    $value = ''
    New-Item -Path $registryPath -Force # will only create if it doesn't exist
    New-ItemProperty -Path $registryPath -Name $name -PropertyType String -Value $value -Force


    Monday, April 15, 2019 9:51 PM