question

TanHuynh-3201 avatar image
0 Votes"
TanHuynh-3201 asked TanHuynh-3201 answered

How do I modify a registry value with PS with condition?

Hello. I have a query below:

Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' | Get-ItemProperty | where {$.UninstallString -notlike '}' -and $.UninstallString -notlike '"'} | select UninstallString,Value


Output example for UninstallString key: C:\Program Files\WinRAR\uninstall.exe param1,param2

I would like to put " " around the value for the sample result above.

IE. Update UninstallString key to have a value of: "C:\Program Files\WinRAR\uninstall.exe" param1,param2

Thank you in advance.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Hi @TanHuynh-3201 ,

please try this:

 $outputExample = 'C:\Program Files\WinRAR\uninstall.exe param1,param2'
 $params = ((Split-Path -Path $outputExample -Leaf).Split(" "))[1]
 $outputFileAndPath = ($outputExample.replace($params,"")).Trim()
 $outputExampleWithQuotes = ('"{0}"' -f $outputFileAndPath) + " $params"
 $outputExampleWithQuotes


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Hi @TanHuynh-3201 ,

something like this?

 $outputExample = 'C:\Program Files\WinRAR\uninstall.exe param1,param2'
 $outputExampleWithQuotes = '"{0}"' -f $outputExample
 $outputExampleWithQuotes


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TanHuynh-3201 avatar image
0 Votes"
TanHuynh-3201 answered

Thanks Andreas, your result $outputExampleWithQuotes = "C:\Program Files\WinRAR\uninstall.exe param1,param2"

I would like to have $outputExampleWithQuotes = "C:\Program Files\WinRAR\uninstall.exe" param1,param2

Is it possible? Thanks.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TanHuynh-3201 avatar image
0 Votes"
TanHuynh-3201 answered

Works perfectly, thank you so much.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.