Sunday, 2 December 2012

Set-AdminLogon.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script defines a function that sets autologon 
  4. .DESCRIPTION 
  5.     Autologon enables the system to logon after a reboot without 
  6.     you needing to enter credentials. This is an ideal scenario 
  7.     for lab or training room systems. This script defines 
  8.     a function that sets a userid/password and autologon.
  9. .NOTES 
  10.     File Name  : Set-AdminLogon 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     Psh> New-AdminLogon -user cookham\tfl -password 'JerryGarciaR0cks!' 
  18.     Auto logon created for [Cookham\tfl] with password: [JerryGarciaR0cks]          
  19.  
  20. #> 
  21.  
  22. Function New-AdminLogon { 
  23.  
  24. [cmdletbinding()] 
  25. Param( 
  26. [string] $User     = $(Throw 'No user id specified'), 
  27. [string] $Password = $(Throw 'No password specified') 
  28. ) 
  29.  
  30. # Define registry path for autologon 
  31. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 
  32.  
  33. # Set autologon 
  34. Set-ItemProperty -Path $RegPath -Name AutoAdminLogon -Value 1  
  35.  
  36. # Set userid and password 
  37. Set-ItemProperty -Path $RegPath -Name DefaultUserName -Value $User  
  38. Set-ItemProperty -Path $regPath -Name DefaultPassword -Value $Password  
  39.  
  40. # Say nice things and exit! 
  41. Write-Host ("Auto logon [{0}] set to password: [{1}]" -f $user, $password) 
  42. } 
  43.  
  44. Set-AdminLogon -User 'Cookham\tfl' -Password 'JerryGarciaR0cks' 
Technorati Tags: ,

No comments: