Add AD account to local administrator group on a remote computer

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. :+1:t4: :wink:

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. :wink:

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.


The use these commands

$lists = Import-csv -path "the list.csv path "
foreach($list in $lists){
        Invoke-Command -ComputerName $list.computername -ScriptBlock {param($adaccount)Add-LocalGroupMember -Group "administrators" -Member $adaccount} -ArgumentList $lists.ADaccount
            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.

1 Like