Author Posts

February 28, 2018 at 8:24 am

Hi there.

I just wanted to write a really small and easy script but it doesn't seem to work 🙁

I simply just want to give local admin rights.

$computername=Read-Host "enter the computername"
$username=Read-Host "enter the user name you want to give access to (DOMAIN\username)"

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

when I only run the command without the parameters but with filled out values it works fine. As soon as I put in $username it doesn't work anymore and I get the following error message:

+ CategoryInfo : InvalidData: (:) [Add-LocalGroupMember], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.AddLocalGroupMemberCommand

February 28, 2018 at 8:40 am

In this post there is a script you maybe able to use to do this.

https://4sysops.com/archives/add-a-user-to-the-local-administrators-group-on-a-remote-computer/

$DomainName = Read-Host "Domain name:"
$ComputerName = Read-Host "Computer name:"
$UserName = Read-Host "User name:"
$AdminGroup = [ADSI]"WinNT://$ComputerName/Administrators,group"
$User = [ADSI]"WinNT://$DomainName/$UserName,user"
$AdminGroup.Add($User.Path)

February 28, 2018 at 8:52 am

USING LOCAL VARIABLES

$ps = "Windows PowerShell"
Invoke-Command -ComputerName S1 -ScriptBlock {
  Get-WinEvent -LogName $Using:ps
}

February 28, 2018 at 9:00 am

Hello Crovax,

thank you that's exactly what I needed!

yeah, now that I think about it, it seems logical. thanks 🙂