Set/Create Registry ValuesI am trying to search registry values and either create a value if <br/>it's not there or set the cirrect value it should have via the <br/>following function: <br/> <p>function Compare2([string]$TermtoMatch, [string]$RegType, [int] <br/>$RegValue, [string]$RegistryPath) { <br/>        $value = Get-ItemProperty -path $RegistryPath <br/>        if ($value -match $TermtoMatch) { Set-ItemProperty $RegistryPath - <br/>Name $TermtoMatch -value $RegValue } <br/>        Else { New-ItemProperty $RegistryPath -Name $TermtoMatch -value <br/>$RegValue -propertyType RegType }</p> <p> </p> <div class=qt style="">} <br/><br/></div> Here's a snippet of the code calling the function: <br/> <p>$RegistryPath = &quot;HKLM:\SOFTWARE\Intel\LANDesk <br/>\VirusProtect6\CurrentVersion\Storages\FileSystem\RealTimeScan&quot;</p> <p>Compare2(&quot;ConfigRestart&quot;, &quot;dword&quot;, 1, $RegistryPath)</p> <p>Here's the error: <br/>Get-ItemProperty : Cannot bind argument to parameter 'Path' because it <br/>is an empty string. <br/>At C:\script.ps1:2 char:33 <br/>+ $value = Get-ItemProperty -Path &lt;&lt;&lt;&lt; $RegistryPath <br/>The '-match' operator failed: parsing &quot;ConfigRestart dword 1 &quot;HKLM: <br/>\SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion\Storages <br/>\FileSystem\RealTimeScan&quot; - Unrecognized escape sequence \I.. <br/>At C:\script.ps1:3 char:19 <br/>+ if ($value -match &lt;&lt;&lt;&lt; $TermtoMatch) {</p> <p>Any ideas what I'm missing here?  I'm thinking it has something to do <br/>with my casting.  When I manually put the values in for the variables <br/>it seems to work just fine. <br/><br/>Thanks.</p>© 2009 Microsoft Corporation. All rights reserved.Wed, 01 Jul 2009 16:25:23 Zcd3c802e-b19d-4a47-97ac-027991f54e05http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#cd3c802e-b19d-4a47-97ac-027991f54e05http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#cd3c802e-b19d-4a47-97ac-027991f54e05AnthonyP100http://social.technet.microsoft.com/Profile/en-US/?user=AnthonyP100Set/Create Registry ValuesI am trying to search registry values and either create a value if <br/>it's not there or set the cirrect value it should have via the <br/>following function: <br/> <p>function Compare2([string]$TermtoMatch, [string]$RegType, [int] <br/>$RegValue, [string]$RegistryPath) { <br/>        $value = Get-ItemProperty -path $RegistryPath <br/>        if ($value -match $TermtoMatch) { Set-ItemProperty $RegistryPath - <br/>Name $TermtoMatch -value $RegValue } <br/>        Else { New-ItemProperty $RegistryPath -Name $TermtoMatch -value <br/>$RegValue -propertyType RegType }</p> <p> </p> <div class=qt style="">} <br/><br/></div> Here's a snippet of the code calling the function: <br/> <p>$RegistryPath = &quot;HKLM:\SOFTWARE\Intel\LANDesk <br/>\VirusProtect6\CurrentVersion\Storages\FileSystem\RealTimeScan&quot;</p> <p>Compare2(&quot;ConfigRestart&quot;, &quot;dword&quot;, 1, $RegistryPath)</p> <p>Here's the error: <br/>Get-ItemProperty : Cannot bind argument to parameter 'Path' because it <br/>is an empty string. <br/>At C:\script.ps1:2 char:33 <br/>+ $value = Get-ItemProperty -Path &lt;&lt;&lt;&lt; $RegistryPath <br/>The '-match' operator failed: parsing &quot;ConfigRestart dword 1 &quot;HKLM: <br/>\SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion\Storages <br/>\FileSystem\RealTimeScan&quot; - Unrecognized escape sequence \I.. <br/>At C:\script.ps1:3 char:19 <br/>+ if ($value -match &lt;&lt;&lt;&lt; $TermtoMatch) {</p> <p>Any ideas what I'm missing here?  I'm thinking it has something to do <br/>with my casting.  When I manually put the values in for the variables <br/>it seems to work just fine. <br/><br/>Thanks.</p>Tue, 30 Jun 2009 19:20:08 Z2009-06-30T19:20:08Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#2f574e95-fecd-4e6c-9d6d-ae2d71ed008bhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#2f574e95-fecd-4e6c-9d6d-ae2d71ed008bMarco Shawhttp://social.technet.microsoft.com/Profile/en-US/?user=Marco%20ShawSet/Create Registry ValuesWhen you call your function, call it like this:<br/> PS&gt;compare2 &quot;configrestart&quot; &quot;dword&quot; 1 $registrypath<br/> <br/> By putting commas, PowerShell is thinking this is all the first argument and passes it in as an array value.<br/>Wed, 01 Jul 2009 01:20:30 Z2009-07-01T01:20:30Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#a50bdf83-3a19-4896-b1f6-5b12d335a20fhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#a50bdf83-3a19-4896-b1f6-5b12d335a20fMervyn Zhanghttp://social.technet.microsoft.com/Profile/en-US/?user=Mervyn%20ZhangSet/Create Registry ValuesHi,<br/> <br/> Additional to Marco's answer, it’s suggested to run the following commands to get more detailed information and instruction about PowerShell Functions.<br/> <br/> Get-Help about_functions<br/> <br/> Get-Help about_functions_advanced<br/> <br/> Get-Help about_functions_advanced_methods <br/> <br/> Get-Help about_functions_cmdletbindingattribute<br/> <br/> Thanks. <br/> <hr class=sig> This posting is provided &quot;AS IS&quot; with no warranties, and confers no rights.Wed, 01 Jul 2009 02:27:21 Z2009-07-01T02:27:34Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#7c9ca714-f679-4b54-8423-4360532a5525http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#7c9ca714-f679-4b54-8423-4360532a5525Marco Shawhttp://social.technet.microsoft.com/Profile/en-US/?user=Marco%20ShawSet/Create Registry ValuesSome of what Mervyn just suggested requires PowerShell v2 (about_functions_advanced, for example).<br/>Wed, 01 Jul 2009 13:17:43 Z2009-07-01T13:17:43Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#af060d8e-4db8-4652-978a-072c2899b782http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/cd3c802e-b19d-4a47-97ac-027991f54e05#af060d8e-4db8-4652-978a-072c2899b782AnthonyP100http://social.technet.microsoft.com/Profile/en-US/?user=AnthonyP100Set/Create Registry ValuesWow, I feel like a complete idiot.  Thanks you! Wed, 01 Jul 2009 16:25:23 Z2009-07-01T16:25:23Z