I have slopped together bits of PowerShell to remote query a list of machines, stored in a .csv file, for a registry value. If the registry key\'s value is equal to \'1\',
In PowerShell =
is an assignment operator, not a comparison operator. Change this line:
if ($keyValue = "1")
into this:
if ($keyValue -eq "1")
For more information see Get-Help about_Operators.
You're making this way too complicated, BTW. Something like this should suffice:
$keyname = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon'
Import-Csv 'C:\temp\machines.csv' | % {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",
$_.machinename)
$key = $reg.OpenSubkey($keyname)
$value = $key.GetValue('AutoAdminLogon')
if ($value -eq "1") {
$filename = Join-Path "c:\temp\autologin" $_.machinename
try {
touch $filename
$textFile = Get-Item $filename
} catch {
$_
}
}
Write-Host ($_.machinename , $value)
}