2

I currently have a script which looks for a specific program to exist in Add/Remove programs and I would like to add the "Dell Command" into registry to confirm.

#Find the Dell Command Update in Add/Remove Programs
Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | 
% {Get-ItemProperty $_.PsPath} | 
where {$_.Displayname -match "Dell Command"} |
sort Displayname | select DisplayName
5
  • what do you mean by "add dell command"? What should be the expected result? Commented Apr 11, 2022 at 13:49
  • In add or remove programs, I am looking for a program called Dell Command to exist. Since it does, I would like the DisplayName to be turned into a variable and set under "HKLM:\SOFTWARE\" path Commented Apr 11, 2022 at 13:52
  • This helps tons! I was able to add the variable into a path I wanted to however it added it as a REG_DWORD type, I would like it as a string. Commented Apr 11, 2022 at 14:19
  • I tried Set-ItemProperty -Path 'HKLM:\SOFTWARE\' -PropertyType String -Name $variable and got an error Commented Apr 11, 2022 at 14:19
  • What error did you get? Commented Apr 11, 2022 at 16:49

1 Answer 1

1

If you would like to create a key based on the value returned from your search, you can do the following:

$dellCommand = (Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object -Property "DisplayName" -Match "Dell Command").DisplayName
$regKeyPath  = "HKLM:\SOFTWARE\$dellCommand"
    if (-not (Test-Path -Path $regKeyPath)) {
        Write-Output -InputObject "$regKeyPath doesn't exist. Creating key."
        $newKey = New-Item -Path $regKeyPath -Force  #Create the key if it doesn't exist.

        #Add Property values to the key
        #$newKey | New-ItemProperty -Name "blah" -Value "valuevalue" -PropertyType "type" -Force 
    }
    else {
        Write-Output -InputObject "Key already exists: [$dellCommand]."
    }

Here, you can test to see if the key already exists and create it if it doesn't. Since New-Item produces an output of the object, you can use that to pipe into New-ItemProperty if needed to add properties to the key (demonstrated above).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.