Author Posts

March 22, 2018 at 1:05 pm


I wrote the following little script to set local admin rights on a machine.

function set-localadmin {

param (
[Parameter (Position=0,mandatory = $true)]
$computername )

$username=Read-Host "Please type in the emailadresse.:"

Invoke-Command -ComputerName $computername -Command {Add-LocalGroupMember -Group Administratoren -Member $Using:username }


so far so good.
It works on 90% of the machines. Just sometimes I get an error message that Add-LocalGroupMember is not a known cmdlet.
I opened a PSSession onto one of the machines where is doesn't work and found out that it has PSv2 installed.

As far as I know, the cmdlet has been introduced with v3.

Is there a way to make this work independently on which version is installed of the client?

Thank you for your help

Kind Regards

March 22, 2018 at 1:08 pm


How about if you'd use old school net localgroup command to perform the action or at least test if ps version is less than 3 then use net localgroup else go with the one you have already.

March 22, 2018 at 2:18 pm

There is the possibility of updating your powershell, enter this link:

and see if you can upgrade.

March 23, 2018 at 6:50 am


unfortunately I cannot read the link (I dont speak ... spanish? portuguese?)

I tried the following:

 function set-localadmin {

        param (
            [Parameter (Position=0,mandatory = $true)]
            $computername           )

            $username=Read-Host "type in your email adresse e.g.:"

Invoke-Command -ComputerName $computername -Command {net localgroup Administratoren $Using:username /add }


but now it doesn't work at all anymore :/
Is there a way of running v3+ commands remotely on a machine with v2?

March 23, 2018 at 7:20 am

I'm not sure if local admin group is different between the languages. Check it out first by just running net localgroup.
This worked for me:

 function set-localadmin {

        # ComputerName

        # Account

    Invoke-Command -ComputerName $ComputerName -Command {net localgroup Administrators $args[0] /add } -ArgumentList $Identity


March 23, 2018 at 12:58 pm

There was a time I tried using [adsi] to read/add from/to local groups. It was early in PS v2. Try Googling

I found this on a quick search:

usually "Hey scripting Guy" is a great place to start.
Good Luck.