Avatar of dawber39
dawber39
Flag for United States of America asked on

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

PowershellShell Scripting

Avatar of undefined
Last Comment
dawber39

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
marek1712

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
marek1712

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

dawber39

ASKER
Thank you for your explanation - I really appreciate it
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck