Powershell Script

Hi,
I have written a powershell script:
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentV ntersion\Winlogon" /v A /t REG_SZ /d 0 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Policies\System" /v DontDisplayLastUserName /t REG_SZ /d 1 /f
reg add "HKLM\System\CurrentControlSet\Services\LanManServer\Parameters" /v restrictnullsessaccess /t REG_SZ /d 1 / /t REG_DWORD /d 5 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v FilterAdministratorToken /t REG_SZ /d 1 /f
reg add "HKLM\Software\Policies\Microsoft\Windows\EventLog\Security" /v MaxSize /t REG_SZ /d 196608 /f
reg add "HKLM\Software\Policies\Microsoft\Windows\EventLog\system" /v MaxSize /t REG_SZ /d 32768 /f
reg add "HKLM\Software\Policies\Microsoft\Windows\EventLog\application" /v MaxSize /t REG_SZ /d 32768 /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableCAD /t REG_SZ /d 1 /f
reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\CurrentVersion\Policies\System" /v FilterAdministratorToken /t REG_SZ /d 1 /f
reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableUIADesktopToggle /t REG_SZ /d 1 /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_SZ /d 1 /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersiosn\Policies\System" /v ConsentPromptBehaviorUser /t REG_SZ /d 1 /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableInstallerDetection /t REG_SZ /d 1 /f
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DontDisplayLasetUserName /t REG_SZ /d 1 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f
reg add "hklm\system\currentcontrolset\services\wsservice" /v start /t reg_dword /d 4 /f


I need to write another powershell script to verify if all above switches are being set.

Thanks.
zman2013Asked:
Who is Participating?
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.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
zman2013,

Do you want a single result of true/false for the complete set of reg values?
0
zman2013Author Commented:
single result.

thanks.
0
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
This line
reg add "HKLM\System\CurrentControlSet\Services\LanManServer\Parameters" /v restrictnullsessaccess /t REG_SZ /d 1 / /t REG_DWORD /d 5 /f

Open in new window

is wrong, there is certainly another reg add missing here.
The first line is also wrong, but the correction is obvious.
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Example code:
$regval = @'
Key, Name, Value
HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, A, 0
HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Policies\System, DontDisplayLastUserName, 1
HKLM:System\CurrentControlSet\Services\LanManServer\Parameters, restrictnullsessaccess, 1
HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, FilterAdministratorToken, 1 
HKLM:Software\Policies\Microsoft\Windows\EventLog\Security, MaxSize, 196608
HKLM:Software\Policies\Microsoft\Windows\EventLog\system, MaxSize, 32768
HKLM:Software\Policies\Microsoft\Windows\EventLog\application, MaxSize, 32768
HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableCAD, 1
HKLM:Software\Policies\Microsoft\Windows\CurrentVersion\Policies\System, FilterAdministratorToken, 1
HKLM:Software\Policies\Microsoft\Windows\CurrentVersion\Policies\System, EnableUIADesktopToggle, 1
HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System, ConsentPromptBehaviorAdmin, 1
HKLM:Software\Microsoft\Windows\CurrentVersiosn\Policies\System, ConsentPromptBehaviorUser, 1
HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System, EnableInstallerDetection, 1
HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System, DontDisplayLasetUserName, 1
HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server, fDenyTSConnections, 0
HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp, UserAuthentication, 0
HKLM:system\currentcontrolset\services\wsservice, start, 4
'@ | ConvertFrom-Csv

foreach ($val in $regval)
{
  $ok = $false
  Get-Item $val.Key -ea SilentlyContinue |
    ? { $_.Property -eq $val.Name } |
    ? { (Get-ItemProperty $val.Key).$($val.Name) -eq $val.Value } | 
    % { $ok = $true }
  $val | Add-Member NoteProperty "ok" $ok -PassThru
}

Open in new window

This will show each key, valuename, value together with an "ok" column. A value is ok only if it is explicitely set, and has the same value.
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
zman2013Author Commented:
Thanks you so much.
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
Microsoft Legacy OS

From novice to tech pro — start learning today.