Skip to content

Instantly share code, notes, and snippets.

@sqlsimon
Created October 19, 2015 21:58
Show Gist options
  • Select an option

  • Save sqlsimon/1bf8e48cf61d023032b7 to your computer and use it in GitHub Desktop.

Select an option

Save sqlsimon/1bf8e48cf61d023032b7 to your computer and use it in GitHub Desktop.
#
# Script to set the computername to be the same as the name of the virtual machine and turn off password complexity and
# expiration. We do that because we just use this for scrap, throwaway VMs
#
Set-ExecutionPolicy RemoteSigned
Enable-psremoting -Force
$virtualmachinename= (Get-ItemProperty 'HKLM:\software\microsoft\virtual machine\guest\parameters').virtualmachinename
$newvmhostname = $virtualmachinename.ToUpper()
$computer = Get-WmiObject Win32_ComputerSystem
$computer.Rename($newvmhostname)
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name AutoAdminLogon -value 0
# set password complexity off
secedit /export /cfg c:\secpol.cfg
(gc C:\secpol.cfg).replace("PasswordComplexity = 1", "PasswordComplexity = 0") | Out-File C:\secpol.cfg
secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY
rm -force c:\secpol.cfg -confirm:$false
# remove age limit on passwords
net accounts /maxpwage:unlimited
start-sleep 5
Restart-Computer -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment