I runing the following simple powershell command on a remote server. However I need to pass a variable to the NET LOCALGROUP command:
$serverName = "SCO32"
$groupName = "SCO33_Local_Admins"
$Session = New-PSSession -ComputerName $serverName
Invoke-Command -Session $Session -ScriptBlock {
$args[1]
$args[0]
net localgroup administrators domainname\$args[1] /ADD
} -ArgumentList $serverName, $groupName
The arguments are passing correctly as is the remote connection, it just doesn't seem to be able to execute the command because it's trying to use the $args[1] as a literal and not domainname\SCO33_Local_Admins
Thanks in advance.