Hi gurus.
I am very new to powershell and I am looking for a script that will help me add an account in multiple computers at the same time using a csv file., is this possible?
Thanks gurus
Hi gurus.
I am very new to powershell and I am looking for a script that will help me add an account in multiple computers at the same time using a csv file., is this possible?
Thanks gurus
It definitely is.
![]()
You will need the following cmdlets:
It might help using your avorite search engine to search for examples. Iām pretty sure there are a lot of. ![]()
I have also done this with no issues ⦠maybe not the best way, and not 100% PowerShell, but it worked for me in one off situations.
Invoke-Command -ComputerName 'hostname' -ScriptBlock {net localgroup Administrators /add 'domainaccount' /domain}
The main issue with this is Remote PowerShell can be a pain depending on your domain security. You might want to have a look at adding the account(s) via GPO.
Hello Guaro,
You can try this.
first, you need a csv file with Computername,ADaccount like this.
list.csv
Client,Domian\user1
Client2,Domian\user2
Client3,Domian\user3
The use these commands
$lists = Import-csv -path "the list.csv path "
foreach($list in $lists){
try{
Invoke-Command -ComputerName $list.computername -ScriptBlock {param($adaccount)Add-LocalGroupMember -Group "administrators" -Member $adaccount} -ArgumentList $lists.ADaccount
}
catch{
write-host "$list.computername add $lists.ADaccount to Administrators group filed "
}
}
This will not work. $lists is not defined in the remote scriptblock
@krzydoug thank you for remind. I have add the -ArgumentList.