Folgende Funktion erstellt und überschreibt Registry Einträge via Powershell
Function Add-Registry($hive,$path,$type,$name,$data)
{
$ErrorActionPreference= 'silentlycontinue'
$regPath = "$hive`:\$path"
$regEntry = "$hive':\$path\$name"
# Create Path
if(!(Test-Path -path $regPath))
{
New-Item -Path "$regPath" | Out-null
}
#Create Reg
if(!(test-path $regEntry)){
New-ItemProperty -Path $regPath -Name $name -Value $data -PropertyType $type | Out-Null
}
#Update Reg
elseif(test-path $regEntry){
Set-ItemProperty -Path $regPath -Name $name -Value $data -PropertyType $type -Force | Out-Null
}
}
Die Funktion kann beispielsweise für ein automatischen Login verwendet werden:
Add-Registry -hive "HKLM" -path "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -type String -name "AutoAdminLogon" -data "1"
Add-Registry -hive "HKLM" -path "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -type String -name "DefaultUserName" -data "username"
Add-Registry -hive "HKLM" -path "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -type String -name "DefaultPassword" -data "password"