adding local admins

Welcome Forums General PowerShell Q&A adding local admins

This topic contains 3 replies, has 3 voices, and was last updated by

1 year ago.

  • Author
  • #94788

    Points: 1
    Rank: Member

    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

    Points: 69
    Rank: Member

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

    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"

  • #94792

    Points: -19
    Rank: Member


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

      Points: 1
      Rank: Member

      Hello Crovax,

      thank you that's exactly what I needed!

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

The topic ‘adding local admins’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort