Pwershell Script

I am new to Powershell - and I am trying to create a script that will check to see if a registry key exists, if it does - change the value, if it does not exist - then create it and set the value. What I have is below - and it does not work (IWhereas I am new,  am not surprised)
$key = Test-Path HKCU:\Software\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
If $key=False
New-Item –path HKCU:\Software\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters –name AutoShareServer
else
New-Itemproperty -path " HKCU:\Software\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\AutoShareServer  -value  0

Open in new window

dawber39Database Analyst / Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

marek1712Commented:
Slight tweaking required:
$key = Test-Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\AutoShareServer
If ($key -eq $false)
{
    New-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\ -PropertyType DWORD -Name AutoShareServer -Value 0
}
else
{
    New-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\ -PropertyType DWORD -Name AutoShareServer -Value 0
}

Open in new window

- there's no "=" in PoSh. There is "-eq"
- everything has to be enclosed in brackets or parentheses
- you have to specify WHAT type of value you want to create
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marek1712Commented:
Ehh, should be:
$key = Test-Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\AutoShareServer
If ($key.Exists -eq $false)
{
    New-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\ -PropertyType DWORD -Name AutoShareServer -Value 0
}
else
{
    Set-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\ -Name AutoShareServer -Value 0
}

Open in new window

0
dawber39Database Analyst / Application DeveloperAuthor Commented:
Thank you for your explanation - I really appreciate it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.