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. # Define registry path for autologon 
  30. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 
  31.  
  32. # Set autologon 
  33. Set-ItemProperty -Path $RegPath -Name AutoAdminLogon -Value 1  
  34.  
  35. # Set userid and password 
  36. Set-ItemProperty -Path $RegPath -Name DefaultUserName -Value $User  
  37. Set-ItemProperty -Path $regPath -Name DefaultPassword -Value $Password  
  38.  
  39. # Say nice things and exit! 
  40. Write-Host ("Auto logon [{0}] set to password: [{1}]" -f $user, $password
  41.  
  42. Set-AdminLogon -User 'Cookham\tfl' -Password 'JerryGarciaR0cks' 
Technorati Tags: ,

No comments: