Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Set/Create Registry Values

Reply
 
Old 06-30-2009   #1 (permalink)
AnthonyP


 
 

Set/Create Registry Values

I am trying to search registry values and either create a value if
it's not there or set the cirrect value it should have via the
following function:

function Compare2([string]$TermtoMatch, [string]$RegType, [int]
$RegValue, [string]$RegistryPath) {
$value = Get-ItemProperty -path $RegistryPath
if ($value -match $TermtoMatch) { Set-ItemProperty $RegistryPath -
Name $TermtoMatch -value $RegValue }
Else { New-ItemProperty $RegistryPath -Name $TermtoMatch -value
$RegValue -propertyType RegType }
}

Here's a snippet of the code calling the function:

$RegistryPath = "HKLM:\SOFTWARE\Intel\LANDesk
\VirusProtect6\CurrentVersion\Storages\FileSystem\RealTimeScan"

Compare2("ConfigRestart", "dword", 1, $RegistryPath)

Here's the error:
Get-ItemProperty : Cannot bind argument to parameter 'Path' because it
is an empty string.
At C:\script.ps1:2 char:33
+ $value = Get-ItemProperty -Path <<<< $RegistryPath
The '-match' operator failed: parsing "ConfigRestart dword 1 "HKLM:
\SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion\Storages
\FileSystem\RealTimeScan" - Unrecognized escape sequence \I..
At C:\script.ps1:3 char:19
+ if ($value -match <<<< $TermtoMatch) {

Any ideas what I'm missing here? I'm thinking it has something to do
with casting, but when I manually put the values in for the variables
it seems to work just fine.

Thanks!

My System SpecsSystem Spec
Old 07-10-2009   #2 (permalink)
Vadims Podans [MVP]


 
 

Re: Set/Create Registry Values

> Compare2("ConfigRestart", "dword", 1, $RegistryPath)

remove brackets and commas.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv

"AnthonyP" <anthonypetito@xxxxxx> rakstija zinojuma
"news:d84b31c5-4ba2-490f-8082-f590046ff78c@xxxxxx"...
Quote:

> I am trying to search registry values and either create a value if
> it's not there or set the cirrect value it should have via the
> following function:
>
> function Compare2([string]$TermtoMatch, [string]$RegType, [int]
> $RegValue, [string]$RegistryPath) {
> $value = Get-ItemProperty -path $RegistryPath
> if ($value -match $TermtoMatch) { Set-ItemProperty $RegistryPath -
> Name $TermtoMatch -value $RegValue }
> Else { New-ItemProperty $RegistryPath -Name $TermtoMatch -value
> $RegValue -propertyType RegType }
> }
>
> Here's a snippet of the code calling the function:
>
> $RegistryPath = "HKLM:\SOFTWARE\Intel\LANDesk
> \VirusProtect6\CurrentVersion\Storages\FileSystem\RealTimeScan"
>
> Compare2("ConfigRestart", "dword", 1, $RegistryPath)
>
> Here's the error:
> Get-ItemProperty : Cannot bind argument to parameter 'Path' because it
> is an empty string.
> At C:\script.ps1:2 char:33
> + $value = Get-ItemProperty -Path <<<< $RegistryPath
> The '-match' operator failed: parsing "ConfigRestart dword 1 "HKLM:
> \SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion\Storages
> \FileSystem\RealTimeScan" - Unrecognized escape sequence \I..
> At C:\script.ps1:3 char:19
> + if ($value -match <<<< $TermtoMatch) {
>
> Any ideas what I'm missing here? I'm thinking it has something to do
> with casting, but when I manually put the values in for the variables
> it seems to work just fine.
>
> Thanks!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Writing values to Registry General Discussion
Remote HKU registry values PowerShell
Reporting on registry values PowerShell
need some registry values Vista General
Access values y registry Keys PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46