The below script will perform the following :
- Create Local user on each Server
- Set Password for newly created account
- Add newly created Admin account to Local Administrator group
Csv file format is as below:
#Script Title : Create local user on each server and add local user account onto Administrator group
#changes in Script : change csv file path in first line of script
#------------------------------------------------------------------------------------------------------#
$list = Import-CSV "C:\LocalAdmins\testUsers.csv" #change path here..
foreach($Servers in $list) {
try{
$computer = $Servers.ServerName
$user = $Servers.LocalAdminAccount
$pass = $Servers.Password
$objOu = [ADSI]"WinNT://$computer"
$objUser = $objOU.Create("User", $user)
$objUser.setpassword($pass)
$objUser.SetInfo()
$objUser.description = "Local Admin Account"
$objUser.SetInfo()
Write-Host " Admin Account created Successfully for $computer with password as $pass" -ForegroundColor "Green" -BackgroundColor "Black"
$AdminGroup = [ADSI]"WinNT://$computer/Administrators,group"
$AdminGroup.Add("WinNT://$computer/$computer/$user,user")
Write-Host "Account $user added successfully into local adminstrator group on Server $computer" -ForegroundColor "Yellow" -BackgroundColor "Black"
}
Catch
{
Write-Host " Unable to reach $computer Server" -ForegroundColor "yellow" -BackgroundColor "red"
}
}
Hi,
ReplyDeleteif i want to execute this on a local server, how do i have to change the script?
Tamer
For example, i have an exisiting Administrator User with name Administrator, how can i force the script to change the existing password?
Delete