Configure Windows local Guest account


posted by tao.yang
06-01-2009

Downloads: 389
File size: 798 B
Views: 2,025

Embed
Configure Windows local Guest account
  1. $ColAccounts = Get-WmiObject Win32_UserAccount 
  2. $strNewGuestName = "<ENTER_NEW_GUEST_ACCOUNT_NAME_HERE>" 
  3. $strGuestPassword = ConvertTo-SecureString "<ENTER_PASSWORD_HERE>" -AsPlainText -force 
  4. $strGuestPw = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($strGuestPassword)) 
  5. $ColAccounts | foreach-object {  
  6. if (($_.SID.substring(0, 8) -match "S-1-5-21") -and ($_.SID.substring($_.SID.length-3, 3) -match "501")) 
  7. { #Set password 
  8.   $computer = [ADSI] "WinNT://$env:computername,computer" 
  9.   $objGuest = $computer.psbase.children.Find($_.name
  10.   $objGuest.SetPassword($strGuestPw
  11.   #$objGuest.psbase.CommitChanges() 
  12.   #Disable 
  13.   $_.disabled = $true 
  14.   $_.put() | Out-Null 
  15.   #Rename 
  16.   $_.Rename($strNewGuestName) | Out-Null 

In Windows 2003, the local guest account has blank password and by default it is named “Guest". Below is the script I wrote in Powershell to rename the guest account (no matter what the current name is) and reset th password

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.