MilesLogan
asked on
Create local accounts on multiple servers
Hi EE
Anyone have a script that will create multiple accounts on multiple servers?
Accounts.txt will have the account names:
Test1
Test2
Test2
servers listed in servers.txt
oh yeah .. they need to be added to the Local administrator group on each server
Anyone have a script that will create multiple accounts on multiple servers?
Accounts.txt will have the account names:
Test1
Test2
Test2
servers listed in servers.txt
oh yeah .. they need to be added to the Local administrator group on each server
Sure, no problem :)
Chris
# Hold this for later on
$Users = Get-Content accounts.txt
# The WinNT interface is complex at best. This lets us get properties from group members when we need to below.
$Properties = "AdsPath", "Name", "AccountDisabled", "Class", "Description"
[Array]$Select = Invoke-Expression "@{n='Server';e={ `$ServerName }}"
$Select += $Properties | ForEach-Object {
Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember('$_', 'GetProperty', `$null, `$_, `$null) }}"
}
# Loop through the list of servers
Get-Content servers.txt | ForEach-Object {
# If we can ping the server
if (Test-Connection $_ -Quiet -Count 1) {
$ServerName = $_
# Connect to the server. Connection is used to create users.
$Server = [ADSI]"WinNT://$ServerName"
# Connect to the administrators group so we can add members.
$AdminGroup = [ADSI]"WinNT://$ServerName/Administrators, group"
$Users | ForEach-Object {
# Create the user
$User = $Server.Create("user", $_)
# Set a dull password
$User.SetPassword("Password123")
# Save the changes
$User.SetInfo()
# Add the new user to the admin group
$AdminGroup.Add($User.Path)
# Just a little bit of validation to do. This shows all (including new) members of the
# administrators group on the server.
$AdminGroup.Members() | Select-Object $Select
}
} else {
# If ping failed we'll say so.
Write-Warning "Failed to connect to $_"
}
}
Cheers!Chris
Sorry Raheman, I should have refreshed before posting. Hopefully two similar methods are better than one :)
Cheers,
Chris
Cheers,
Chris
Theres a script here to do it with the Password Never Expires flag set.
http://mobile.experts-exchange.com/questions/26953782/Anyone-got-a-vbs-script-to-create-multiple-user-accounts-local.html
Rob.
http://mobile.experts-exchange.com/questions/26953782/Anyone-got-a-vbs-script-to-create-multiple-user-accounts-local.html
Rob.
You may find my accepted solution helpful in below link -
https://www.experts-exchange.com/questions/28381551/script-batch-file-windows-7-username-create-script.html
https://www.experts-exchange.com/questions/28381551/script-batch-file-windows-7-username-create-script.html
ASKER
Thanks guys .. I tried Chris since it has mode details and more function .. Chris can you
also add the code to add a description to the new accounts ?
also add the code to add a description to the new accounts ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is an easy batch file way to do this, if you allow access to the admin$ share, and get a copy of SysInternals PSExec. (http://technet.microsoft.c om/en-us/s ysinternal s/bb897553 ).
Coralon
for /f %f in (servers.txt) do for /f %A in (accounts.txt) do psexec \\%f net user %A <temppassword> /add
for /f %f in (servers.txt) do for /f %A in (accounts.txt) do psexec \\%f net localgroup administrators %A /add
Coralon
ASKER
No worries , thanks you !! This saved me alot of time
function create-account ([string]$accountName, [string]$accountDescriptio
$comp = [adsi]"WinNT://$hostname"
$user = $comp.Create("User", $accountName)
$user.SetPassword("change"
$user.SetInfo()
$user.description = $accountDescription
$user.SetInfo()
$objOU = [ADSI]("WinNT://$hostname/
$objOU.add("WinNT://$hostn
}
$servers =get-content "C:\temp\servers.txt"
foreach ($server in $servers)
{
$accounts = Get-Content "C:\temp\accounts.txt"
foreach ($account in $accounts)
{
create-account $account "" $server
}
}
Checked using dos command:
net user
net user Test1