Hello Im trying to add domain users to the local machine administrator group with the script below
$global:user = Read-Host "what is the username"
$machine = Read-Host "what is the machine name"
Invoke-Command -ComputerName $machine -ScriptBlock {
net localgroup administrators $global:user /add }
But when i run it i receive the below error
The group already exists.
+ CategoryInfo : NotSpecified: (The group already exists.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
More help is available by typing NET HELPMSG 2223.
but if i put the name of the user in "user" it work
$global:user = Read-Host "what is the username"
$machine = Read-Host "what is the machine name"
Invoke-Command -ComputerName $machine -ScriptBlock {
net localgroup administrators dacto /add }
Is there a way to help me fix my script so that it can use the information from the read-host input instead of me having to do it manually
Thank you