简体   繁体   中英

Powershell to create a new registry value

I would like to create a new registry value in this path "Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Security" It should be a new "DWORD" inside the security key called "VBAWarnings" and value should be one.

I have tried the following way:

New-ItemProperty –Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Security" -Value "VBAWarnings"  -PropertyType "DWORD"

However it is not creating anything and not sure whats per error message I have "

((Get-Process MicrosoftEdgeCP -ErrorA.ps1:1 char:124
+ ... ce\16.0\Outlook\Security" -Value "VBAWarnings"  -PropertyType "DWORD"
+                                                                         ~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString"

This has been correctly answered by @AdminOfThings and @Neko Musume. I'd like to add the step of displaying the finished code, as well as how to address this in the future. First, the code:

New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Security" -Name "VBAWarnings" -PropertyType "DWORD" -Value "1"

Whenever you are creating new powershell code, use Powershell ISE (Integrated Scripting Engine). The nice thing about this interface is that it has intellisense, popping up useful things are you're writing your code.

To replicate this, in the scripting portion of the ISE window (the white part), I typed:

New-Itemproperty -

When I added the dash, it gave me a list of items to choose from. I chose the top one, which was path. I then continued the code:

New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Security" -

Again, it showed me a list of options, and I went with the top choice, Name. Continued until I saw the default choices (things like -force). This is a good rule of thumb when you're working with commands in powershell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM