Gone are the days when they had to follow a page of instructions for configuring each system.
My first script is to enable AutoAdminLogon in the registry and give it the user and password required.
For Windows 7
Type: PowerShell
$Regkey= "HKLM:\Software\Microsoft\Windows NT\Currentversion\WinLogon"
$DefaultUserName = 'Administrator'
$DefaultPassword = 'P@ssword'
# This function just gets $true or $false
function Test-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
$key -and $null -ne $key.GetValue($name, $null)
}
# Gets the specified registry value or $null if it is missing
function Get-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
if ($key) {$key.GetValue($name, $null)}
}
#AutoAdminLogon Value
$AALRegValExist = Test-RegistryValue $Regkey AutoAdminLogon
$AALRegVal = Get-RegistryValue $RegKey AutoAdminLogon
if ($AALRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 1 }
elseif ($AALRegVal -ne 1) { Set-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 1 }
#DefaultUserName Value
$DUNRegValExist = Test-RegistryValue $Regkey DefaultUserName
$DUNRegVal = Get-RegistryValue $RegKey DefaultUserName
if ($DUNRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
elseif ($DUNRegVal -ne $DefaultUserName) { Set-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
#DefaultPassword Value
$DPRegValExist = Test-RegistryValue $Regkey DefaultPassword
$DPRegVal = Get-RegistryValue $RegKey DefaultPassword
if ($DPRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
elseif ($DPRegVal -ne $DefaultPassword) { Set-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
$DefaultUserName = 'Administrator'
$DefaultPassword = 'P@ssword'
# This function just gets $true or $false
function Test-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
$key -and $null -ne $key.GetValue($name, $null)
}
# Gets the specified registry value or $null if it is missing
function Get-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
if ($key) {$key.GetValue($name, $null)}
}
#AutoAdminLogon Value
$AALRegValExist = Test-RegistryValue $Regkey AutoAdminLogon
$AALRegVal = Get-RegistryValue $RegKey AutoAdminLogon
if ($AALRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 1 }
elseif ($AALRegVal -ne 1) { Set-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 1 }
#DefaultUserName Value
$DUNRegValExist = Test-RegistryValue $Regkey DefaultUserName
$DUNRegVal = Get-RegistryValue $RegKey DefaultUserName
if ($DUNRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
elseif ($DUNRegVal -ne $DefaultUserName) { Set-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
#DefaultPassword Value
$DPRegValExist = Test-RegistryValue $Regkey DefaultPassword
$DPRegVal = Get-RegistryValue $RegKey DefaultPassword
if ($DPRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
elseif ($DPRegVal -ne $DefaultPassword) { Set-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
Give the Default Username and Password, and execute with PS.
The reason that there is a registry value test is that powershell has two different commands for creating a new registry value (New-ItemProperty) and changing on (Set-ItemProperty)
The following script is for disabling the AutoAdminLogon. The user and password is cleared, and the AutoAdminLogon registry value is changed to 0.
$Regkey= "HKLM:\Software\Microsoft\Windows NT\Currentversion\WinLogon"
$DefaultUserName = ''
$DefaultPassword = ''
# This function just gets $true or $false
function Test-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
$key -and $null -ne $key.GetValue($name, $null)
}
# Gets the specified registry value or $null if it is missing
function Get-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
if ($key) {$key.GetValue($name, $null)}
}
#AutoAdminLogon Value
$AALRegValExist = Test-RegistryValue $Regkey AutoAdminLogon
$AALRegVal = Get-RegistryValue $RegKey AutoAdminLogon
if ($AALRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 0 }
elseif ($AALRegVal -ne 0) { Set-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 0 }
#DefaultUserName Value
$DUNRegValExist = Test-RegistryValue $Regkey DefaultUserName
$DUNRegVal = Get-RegistryValue $RegKey DefaultUserName
if ($DUNRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
elseif ($DUNRegVal -ne $DefaultUserName) { Set-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
#DefaultPassword Value
$DPRegValExist = Test-RegistryValue $Regkey DefaultPassword
$DPRegVal = Get-RegistryValue $RegKey DefaultPassword
if ($DPRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
elseif ($DPRegVal -ne $DefaultPassword) { Set-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
$DefaultUserName = ''
$DefaultPassword = ''
# This function just gets $true or $false
function Test-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
$key -and $null -ne $key.GetValue($name, $null)
}
# Gets the specified registry value or $null if it is missing
function Get-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
if ($key) {$key.GetValue($name, $null)}
}
#AutoAdminLogon Value
$AALRegValExist = Test-RegistryValue $Regkey AutoAdminLogon
$AALRegVal = Get-RegistryValue $RegKey AutoAdminLogon
if ($AALRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 0 }
elseif ($AALRegVal -ne 0) { Set-ItemProperty -Path $Regkey -Name AutoAdminLogon -Value 0 }
#DefaultUserName Value
$DUNRegValExist = Test-RegistryValue $Regkey DefaultUserName
$DUNRegVal = Get-RegistryValue $RegKey DefaultUserName
if ($DUNRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
elseif ($DUNRegVal -ne $DefaultUserName) { Set-ItemProperty -Path $Regkey -Name DefaultUserName -Value $DefaultUserName }
#DefaultPassword Value
$DPRegValExist = Test-RegistryValue $Regkey DefaultPassword
$DPRegVal = Get-RegistryValue $RegKey DefaultPassword
if ($DPRegValExist -eq $null) { New-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
elseif ($DPRegVal -ne $DefaultPassword) { Set-ItemProperty -Path $Regkey -Name DefaultPassword -Value $DefaultPassword }
You shouldn't store passwords in the registry in plaintext.
ReplyDelete