1

Enter Values

The image above is my issue. After I click run with PowerShell it asks for variables meanwhile I have it set in the following code:

$name = "Action"$value = 0x00000001 New-ItemProperty -Path $f1_key_path    -Name $name    -Value $value    -PropertyType DWORD

I was hoping by declaring these variables I would be able to not have to use the terminal to write the inputs into the script. I have more cmdlets like this and they are all asking for input is there any reason why? If so how could I get it to use my variables I declared.

askedAug 1, 2023 at 20:32
Wandering's user avatar

1 Answer1

3

In order to have parameters on different lines like you have there, the last character on a line (except on the last line) needs to be a backtick (`). So your code should look like:

$name = "Action"$value = 0x00000001 New-ItemProperty -Path $f1_key_path `    -Name $name `    -Value $value `    -PropertyType DWORD

Make very sure that there is no space or anything after the backtick. Personally I advise against doing this. I would recommend building a hashtable, and thensplatting that hashtable like this:

$NewItemParams = @{    Name = 'Action'    Value = 0x00000001    Path = $f1_key_path    PropertyType = 'DWORD'}New-ItemProperty @NewItemParams
mklement0's user avatar
mklement0
453k68 gold badges729 silver badges989 bronze badges
answeredAug 1, 2023 at 20:42
TheMadTechnician's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it was very helpful. I was generally confused about the setup for the PowerShell Script I also put everything in one line. It also worked.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.