Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [String]$Username = 'customadmin'
  2. [String]$Password = 'RakksFr0mR3DD1T'
  3.  
  4. $UsernameQuery = Get-WmiObject Win32_UserAccount -Filter "Name = '$Username'"
  5. $BuiltinQuery = Get-WmiObject Win32_UserAccount -Filter "SID like 'S-1-5-21-%-500'"
  6.  
  7. # $Username exists.
  8. if ($UsernameQuery -ne $null){
  9.  
  10.     # Check if $Username is builtin account.
  11.  
  12.         # It is the built-in administrator account. Configuring it.
  13.     if ($BuiltinQuery.Name -eq $Username){
  14.  
  15.         Net User $Username $Password
  16.         Net User $Username /Active:Yes
  17.  
  18.         }
  19.    
  20.         # It isn't the built-in administrator account. Delete it then configure builtin account.
  21.     elseif ($BuiltinQuery.Name -ne $Username){
  22.        
  23.         Net User $Username /Delete
  24.         $BuiltinQuery.Rename($Username)
  25.         Net User $Username $Password
  26.         Net User $Username /Active:Yes
  27.        
  28.         }
  29.  
  30. }
  31.  
  32. # $Username doesn't exist.
  33. elseif ($UsernameQuery -eq $null){
  34.    
  35.     # Configure builtin administrator account.
  36.  
  37.     $BuiltinQuery.Rename($Username)
  38.     Net User $Username $Password
  39.     Net User $Username /Active:Yes
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement