Not too sure why the below is not working. Basically, there are multiple elseif statements based on the values of keys.
I tested a server with setting $valuePassword
equal to random characters I put in and I also set $valueAutoLogin
to '1'
. But, the result I get is below which does not show anything?
Also - can you think of a better way of doing this instead of multiple elseif statments?
>
clear
Import-Module PSRemoteRegistry
$computers = Get-Content -Path C:\MANNY\Servers.txt
foreach($computer in $computers)
{
Write-Host "Checking $computer"
#Check if key exists
$valuePassword = Get-RegValue -ComputerName $Computer -Key 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Value DefaultPassword
$valueAutoLogin = Get-RegValue -ComputerName $Computer -Key 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Value AutoAdminLogon
if($valuePassword -eq $null -and $valueAutoLogin -eq $null)
{Write-Host "$computer not set"}
elseif($valuePassword -notcontains $null -and $valueAutoLogin -eq $null)
{Write-Host "$computer has Password set"}
elseif($valuePassword -eq $null -and $valueAutoLogin -eq '1')
{Write-Host "$computer has Autologin set but not password"}
elseif($valuePassword -notcontains $null -and $valueAutoLogin -eq '1')
{Write-Host "$computer has Autologin set and password set - AUTOLOGIN IS POSSIBLY SET"}
}
> RESULT:
Checking SV160666
Checking SV160668
Checking SV160670
Checking SV160672
Checking SV160674
Checking SV180435
Checking SV193865
Checking SV193885