Sunday, 2 December 2012

New-AutoAdminLogon.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. It does NOT 
  9.     check to see if the value entries already exist. 
  10. .NOTES 
  11.     File Name  : Set-AutoAdminLogon 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17. .EXAMPLE 
  18.     Psh> Set-AutoAdminLogon -user cookham\tfl -password 'JerryGarciaR0cks!' 
  19.     Auto logon set for [Cookham\tfl] with password: [JerryGarciaR0cks]          
  20.  
  21. #> 
  22.  
  23. Function Set-AdminLogon { 
  24.  
  25. [cmdletbinding()] 
  26. Param( 
  27. [string] $User     = $(Throw 'No user id specified'), 
  28. [string] $Password = $(Throw 'No password specified'
  29.  
  30. # Define registry path for autologon 
  31. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 
  32.  
  33. # Set autologon 
  34. New-ItemProperty -Path $RegPath -Name AutoAdminLogon -Value 1 -EA 0 
  35.  
  36. # Set userid and password 
  37. New-ItemProperty -Path $RegPath -Name DefaultUserName -Value $User -EA 0 
  38. New-ItemProperty -Path $regPath -Name DefaultPassword -Value $Password -EA 0 
  39.  
  40. # Say nice things and exit! 
  41. Write-Host ("Auto logon set for [{0}] with password: [{1}]" -f $user, $password
  42.  
  43. Set-AdminLogon -User 'Cookham\tfl' -Password 'JerryGarciaR0cks' 
Technorati Tags: ,

No comments: