Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- creating local users using a xml file as source with powershell scripting
- # To run this script use: & "C:UsersrLisdonkDesktopToServerTest.ps1"
- $computerName = "USSECAVDSPDWK27"
- $serviceAccountWebName = "saAsaWeb"
- $serviceAccountWebPassword = "MyPassword123"
- "Get computer info"
- $computer = [ADSI]("WinNT://" + $computerName + ",computer")
- "Determine if user [saAsaWeb] exists"
- $serviceAccount = [ADSI]("WinNT://" + $computerName + "/$serviceAccountWebName" + ",user")
- if(!$serviceAccount.Name)
- {
- "Create user [saAsaWeb]"
- $user = $computer.Create("user", $serviceAccountWebName)
- "Set password"
- $user.SetPassword($serviceAccountWebPassword)
- $user.SetInfo()
- "Disable [User must change password at next logon]"
- $user.PasswordExpired = 0
- $user.SetInfo()
- "Enable [Password never expires]"
- $wmiuser = Get-WmiObject -class "Win32_UserAccount" -filter "name=’$serviceAccountWebName’"
- $wmiuser.PasswordExpires = $false
- $wmiuser.Put()
- }
- $wmiuser = Get-WmiObject Win32_UserAccount -filter "LocalAccount=True AND name=`'$serviceAccountWebName`'"
Add Comment
Please, Sign In to add comment