3
I am trying to add registry keys to Windows 10 using a PowerShell script. The key in the registry must have double quotes included in the data field so I understand I must escape the double quote with a backslash.
The following example command throws a syntax error when executed in Powershell but works perfectly in a Command prompt window:
REG ADD \\COMPUTER1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\dcpm-notify /v ImagePath /t REG_EXPAND_SZ /d "\"C:\Program Files\Dell\CommandPowerManager\NotifyService.exe\"" /f
I have tried changing the escape characters to ` and using """ etc but I cannot get any combination to work in a PowerShell.
Any suggestions greatly appreciated.
1"The following example command throws a syntax error" - If you want help provide your error. – Ramhound – 2016-12-07T18:07:31.653
Why don't you just use the shortname for Program Files instead of dealing with a space, although your underline problem, is your syntax is wrong. You have unmatched escape characters "" through your directory string. You can also use
%ProgramFiles%
but resolve your directory problem first. – Ramhound – 2016-12-07T18:10:39.137You can do something like
$ProgramFiles = "${Env:ProgramFiles}"
to make it simple – Ramhound – 2016-12-07T18:13:02.347Thanks for your comments. The only error thrown is "Syntrax Error - check REG ADD /?" – GOB – 2016-12-07T18:18:02.513
Unfortunately this is a generic script to add double quotes to any unquoted paths with spaces. It's a security requirement. Not all will be Program files. – GOB – 2016-12-07T18:20:08.530
Have you confirmed you actually NEED to include those wrapping quotes? – Ƭᴇcʜιᴇ007 – 2016-12-07T18:24:55.127
@Techie007 yes afraid so. – GOB – 2016-12-07T18:27:51.613
Why not use single quotes around the text, so double quotes can be inserted normally? EG: 'my var with "quotes"' – LPChip – 2016-12-07T21:18:13.927