0

Is there any solution to add(import) values to the registry from here string.

$regString = @"
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
... blha blha blha ....
"@
Some-FunctionOrCommandThatAcceptHereSTRtoReg $regString
2
  • 1
    Why not using reg.exe? Commented Jul 14, 2023 at 9:07
  • 4
    You could write the string to a temporary file on disk and then run reg.exe import against that file. Commented Jul 14, 2023 at 11:25

1 Answer 1

2

+++ solution A (Mathias R. Jessen)

Just write HereString to file then use it in reg

function HereString-ToRegistry{
    param ([Parameter()] [string] $Regstr)
    $tmp = New-TemporaryFile
    $Regstr | Out-File $tmp
    reg import $tmp.FullName
}
$regstr1 = @"
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\PropertyBag]
"ThisPCPolicy"="Hide"
"@
HereString-ToRegistry -Regstr $regstr1
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.