Help with Add and remove group

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 9 months, 2 weeks ago.

  • Author
    Posts
  • #54976
    Profile photo of ohlssrog
    ohlssrog
    Participant

    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

    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    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.

You must be logged in to reply to this topic.