Help with Add and remove group

Welcome Forums General PowerShell Q&A Help with Add and remove group

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

 
Participant
2 years, 3 months ago.

  • Author
    Posts
  • #54976

    Participant
    Points: 0
    Rank: Member

    Hi all.

    I need help with a job we have here, its about to remove a specific Domain local group from local administrators and add another global group on clients and servers.

    I have successfully created an script that add the new global group. Thanks to https://gallery.technet.microsoft.com/scriptcenter/Add-AD-UserGroup-to-Local-fe5e9239

    just run \Set-ADAccountasLocalAdministrator.ps1 -InputFile C:\ListofComputers.txt -Trustee domain\groupname

    BUT the problem is that i cant find any script for the removal, i have tried
    https://blogs.technet.microsoft.com/heyscriptingguy/2005/10/24/how-can-i-remove-a-group-from-the-local-administrators-group/

    But get same error otherfilled in here

    Like
    At C:\PS_Scripts\remove_sedlgwksadmins.ps1:3 char:38
    + Set objAdmins = GetObject(“WinNT://” & strComputer & “/Administrators ...
    + ~
    Unexpected token '&' in expression or statement.
    At C:\PS_Scripts\remove_sedlgwksadmins.ps1:3 char:37
    + Set objAdmins = GetObject(“WinNT://” & strComputer & “/Administrators ...
    + ~
    Missing closing ')' in expression.
    At C:\PS_Scripts\remove_sedlgwksadmins.ps1:3 char:38
    + Set objAdmins = GetObject(“WinNT://” & strComputer & “/Administrators ...
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.
    At C:\PS_Scripts\remove_sedlgwksadmins.ps1:3 char:52
    + Set objAdmins = GetObject(“WinNT://” & strComputer & “/Administrators ...
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.
    At C:\PS_Scripts\remove_sedlgwksadmins.ps1:3 char:71
    + ... t objAdmins = GetObject(“WinNT://” & strComputer & “/Administrators”)
    + ~
    Unexpected token ')' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

  • #54978

    Participant
    Points: 438
    Helping Hand
    Rank: Contributor

    That code is VBScript, not Powershell. Take a look at this example:

    https://mcpmag.com/articles/2015/05/28/managing-local-groups-in-powershell.aspx

  • #54984

    Participant
    Points: 38
    Rank: Member

    May I ask why you're not using Group Policy for this? It should be much simpler to configure and easier to consistently enforce across your domain than a PowerShell solution.

The topic ‘Help with Add and remove group’ is closed to new replies.