adding local admins

This topic contains 3 replies, has 3 voices, and was last updated by  kate Ritter 2 months, 3 weeks ago.

  • Author
    Posts
  • #94788

    kate Ritter
    Participant

    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

  • #94791

    Simon B
    Participant

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

    $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)

  • #94792

    Crovax
    Participant

    USING LOCAL VARIABLES

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

      kate Ritter
      Participant

      Hello Crovax,

      thank you that's exactly what I needed!

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

You must be logged in to reply to this topic.