Add value to registry key


posted by Richard Giles
02-17-2009

Downloads: 583
File size: 1.2kB
Views: 5,232

Embed
Add value to registry key
  1. <?xml version="1.0"?> 
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"
  3.     <CodeSnippet Format="1.0.0"
  4.         <Header> 
  5.             <Title>Add value to registry key</Title> 
  6.             <Shortcut /
  7.             <Description>Adds a value and content to a registry key</Description> 
  8.             <Author>Dr. Tobias Weltner http://www.powershell.de</Author> 
  9.             <SnippetTypes> 
  10.                 <SnippetType>Expansion</SnippetType> 
  11.             </SnippetTypes> 
  12.         </Header> 
  13.         <Snippet> 
  14.             <Declarations> 
  15.                 <Literal> 
  16.                     <ID>param1</ID> 
  17.                     <ToolTip>key you want to add a value to. This key MUST exist.</ToolTip> 
  18.                     <Default>HKCU:\Software\Test</Default> 
  19.                 </Literal> 
  20.                 <Literal> 
  21.                     <ID>param2</ID> 
  22.                     <ToolTip>Name of new value</ToolTip> 
  23.                     <Default>Test</Default> 
  24.                 </Literal> 
  25.                 <Literal> 
  26.                     <ID>param3</ID> 
  27.                     <ToolTip>Value to store in new value</ToolTip> 
  28.                     <Default>Testvalue</Default> 
  29.                 </Literal> 
  30.             </Declarations> 
  31.             <Code Language="PowerShell" Kind="0"><![CDATA[if (Test-Path '$param1$') { 
  32.     New-ItemProperty '$param1$' -Name '$param2$' -Value '$param3$' 
  33.     "Added Key-Value pair to registry key" 
  34. } else
  35.     "Registry key $param1$ does not exist." 
  36. }]]></Code> 
  37.         </Snippet> 
  38.     </CodeSnippet> 
  39. </CodeSnippets> 
Filed under: , ,

Adds a value and content to a registry key

Copyright 2012 PowerShell.com. All rights reserved.