# Enable-PasswordlessPS.ps1 # Enables passwordless PowerShell connections to VM # Run this INSIDE the VM #Requires -RunAsAdministrator Write-Host "Configuring VM for passwordless PowerShell access..." -ForegroundColor Cyan # 1. Update password policy FIRST to allow blank passwords Write-Host "Updating password security policy..." -ForegroundColor Yellow $tempFile = "$env:TEMP\secpol.cfg" secedit /export /cfg $tempFile /quiet $content = Get-Content $tempFile $content = $content -replace "PasswordComplexity = 1", "PasswordComplexity = 0" $content = $content -replace "MinimumPasswordLength = \d+", "MinimumPasswordLength = 0" $content | Set-Content $tempFile secedit /configure /db c:\windows\security\local.sdb /cfg $tempFile /areas SECURITYPOLICY /quiet Remove-Item $tempFile -Force Write-Host "[OK] Security policy updated" -ForegroundColor Green # 2. Set Administrator to blank password (now allowed by policy) Write-Host "Setting blank password for Administrator..." -ForegroundColor Yellow $blankPassword = New-Object System.Security.SecureString Set-LocalUser -Name "Administrator" -Password $blankPassword -PasswordNeverExpires $true Write-Host "[OK] Blank password set" -ForegroundColor Green # 3. Enable blank passwords for network access (registry) Write-Host "Enabling network access with blank passwords..." -ForegroundColor Yellow Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "LimitBlankPasswordUse" -Value 0 -Type DWord Write-Host "[OK] Registry updated" -ForegroundColor Green # 4. Enable PowerShell Remoting Write-Host "Enabling PowerShell Remoting..." -ForegroundColor Yellow Enable-PSRemoting -Force -SkipNetworkProfileCheck Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force Write-Host "[OK] PS Remoting enabled" -ForegroundColor Green # 5. Configure WinRM for basic auth Write-Host "Configuring WinRM..." -ForegroundColor Yellow winrm set winrm/config/service/auth '@{Basic="true"}' winrm set winrm/config/service '@{AllowUnencrypted="true"}' winrm set winrm/config/client/auth '@{Basic="true"}' Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $true Write-Host "[OK] WinRM configured" -ForegroundColor Green # 6. Firewall rules Write-Host "Configuring firewall..." -ForegroundColor Yellow Enable-NetFirewallRule -Name "WINRM-HTTP-In-TCP" New-NetFirewallRule -Name "PowerShell-Remoting" -DisplayName "PowerShell Remoting" -Protocol TCP -LocalPort 5985,5986 -Direction Inbound -Action Allow -ErrorAction SilentlyContinue Write-Host "[OK] Firewall configured" -ForegroundColor Green # 7. Remove Lock Screen, Sign-in Screen and Ctrl+Alt+Del Write-Host "Disabling all login screens..." -ForegroundColor Yellow # Auto-logon configuration with blank password $RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" Set-ItemProperty -Path $RegPath -Name "AutoAdminLogon" -Value "1" -Type String Set-ItemProperty -Path $RegPath -Name "DefaultUserName" -Value "Administrator" -Type String Set-ItemProperty -Path $RegPath -Name "DefaultPassword" -Value "" -Type String Set-ItemProperty -Path $RegPath -Name "DefaultDomainName" -Value "." -Type String Set-ItemProperty -Path $RegPath -Name "ForceAutoLogon" -Value "1" -Type String Set-ItemProperty -Path $RegPath -Name "DisableCAD" -Value 1 -Type DWord Set-ItemProperty -Path $RegPath -Name "AutoLogonCount" -Value 0 -Type DWord # Remove password expiry notification Set-ItemProperty -Path $RegPath -Name "PasswordExpiryWarning" -Value 0 -Type DWord # Disable sign-in screen and last user New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies" -Name "System" -Force -ErrorAction SilentlyContinue | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "DisableCAD" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "dontdisplaylastusername" -Value 0 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "shutdownwithoutlogon" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "NoLogonBackgroundImage" -Value 1 -Type DWord # Disable lock screen completely New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "Personalization" -Force -ErrorAction SilentlyContinue | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization" -Name "NoLockScreen" -Value 1 -Type DWord # Disable sign-in screen animation New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" -Force -ErrorAction SilentlyContinue | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" -Name "AnimationDisabled" -Value 1 -Type DWord # Fast user switching off New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies" -Name "Explorer" -Force -ErrorAction SilentlyContinue | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideFastUserSwitching" -Value 1 -Type DWord # Disable lock workstation New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies" -Name "System" -Force -ErrorAction SilentlyContinue | Out-Null Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -Name "DisableLockWorkstation" -Value 1 -Type DWord # Disable lock screen timeout Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\7516b95f-f776-4464-8c53-06167f40cc99\8EC4B3A5-6868-48c2-BE75-4F3044BE88A7" -Name "Attributes" -Value 2 -Type DWord -Force -ErrorAction SilentlyContinue # Disable screen saver Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "ScreenSaveActive" -Value "0" -Force -ErrorAction SilentlyContinue Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "ScreenSaverIsSecure" -Value "0" -Force -ErrorAction SilentlyContinue # Power settings - never turn off display or sleep powercfg /change monitor-timeout-ac 0 powercfg /change monitor-timeout-dc 0 powercfg /change standby-timeout-ac 0 powercfg /change standby-timeout-dc 0 Write-Host "[OK] Lock screen disabled" -ForegroundColor Green # 8. User Account Control - disable prompts Write-Host "Disabling UAC prompts..." -ForegroundColor Yellow Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLUA" -Value 0 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value 0 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "PromptOnSecureDesktop" -Value 0 -Type DWord Write-Host "[OK] UAC disabled" -ForegroundColor Green # 9. Restart WinRM Write-Host "Restarting WinRM service..." -ForegroundColor Yellow Restart-Service WinRM Write-Host "[OK] WinRM restarted" -ForegroundColor Green # Get VM's IP $ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -like "192.168.*" }).IPAddress Write-Host "`n===============================================" -ForegroundColor Green Write-Host "Passwordless Access Configured!" -ForegroundColor Green Write-Host "===============================================" -ForegroundColor Green Write-Host "`nVM IP: $ip" -ForegroundColor Cyan Write-Host "`nFrom Hyper-V host, connect with:" -ForegroundColor Yellow Write-Host ' $cred = New-Object PSCredential("Administrator", (New-Object System.Security.SecureString))' -ForegroundColor White Write-Host " Enter-PSSession -ComputerName $ip -Credential `$cred" -ForegroundColor White Write-Host "`nOr for VM name (PowerShell Direct):" -ForegroundColor Yellow Write-Host " Enter-PSSession -VMName 'YourVMName' -Credential `$cred" -ForegroundColor White Write-Host "`n[IMPORTANT] Restart VM for all changes to take effect!" -ForegroundColor Red Write-Host "Run: Restart-Computer -Force" -ForegroundColor Yellow