SHARE
TWEET

Untitled

a guest Jun 8th, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Username = "ansible"
  2. $Password = "Welcome123"
  3.  
  4. $group = "Administrators"
  5.  
  6. $adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
  7. $existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
  8.  
  9. if ($existing -eq $null) {
  10.  
  11.     Write-Host "Creating new local user $Username."
  12.     & NET USER $Username $Password /add /y /expires:never
  13.    
  14.     Write-Host "Adding local user $Username to $group."
  15.     & NET LOCALGROUP $group $Username /add
  16.  
  17. }
  18. else {
  19.     Write-Host "Setting password for existing local user $Username."
  20.     $existing.SetPassword($Password)
  21. }
  22.  
  23. Write-Host "Ensuring password for $Username never expires."
  24. & WMIC USERACCOUNT WHERE "Name='$Username'" SET PasswordExpires=FALSE
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top