Frilanser: RikkaAutomate
Del:
Rapporter innlegg

Script

I hope I understood correctly what you wanted the script to do. Change line 1 in the script to specify your file. The file has to be in the same format as you wrote, with no headers. It will take all members from the reference group, and add them to the destination group unless they are a member of the difference group. Correct? It's a weird format to update it in, breaks the formatting a bit, but here's a PDF.

Offentlig avklaringstavle

  • RikkaAutomate
    RikkaAutomate
    • 2 år siden

    I think you should just stick to the first script I wrote in the PDF, because it will do exactly that, and it will still work even if the difference group would be empty.

    It will get the users and computers recursively, yeah.

    • 2 år siden
  • cifwig
    Konkurranseholder
    • 2 år siden

    Another thing has come to my mind. As the destination-group should finally contain only users and computers, only users and computers should be read recusivly of reference-group and the difference-group. Would that be possible?

    • 2 år siden
  • cifwig
    Konkurranseholder
    • 2 år siden

    Not sure, if I clearly understand your last comment, because you use other group-names. I will try to describe it again:
    The reference-group has many members. The difference-group has a few members. The destination-group should be filled with those members from the reference-group, which are no members in the difference-group.

    • 2 år siden
  • RikkaAutomate
    RikkaAutomate
    • 2 år siden

    And this simplified version will not work if either of the groups either don't exist, or if they are empty.

    • 2 år siden
  • RikkaAutomate
    RikkaAutomate
    • 2 år siden

    But it's sort of the opposite what I wrote, so with your piece of code, you will get the members from group B that are not in group A and remove those from group C

    • 2 år siden
  • RikkaAutomate
    RikkaAutomate
    • 2 år siden

    Yeah sure, I think you meant remove-adgroupmember "GroupC" though, right? (The third element in the import file)


    Here is the full script:

    $listPath = "C:\temp\list.txt"
    $list = get-content $listPath
    foreach($row in $list){
    $split = $row.Split(",")
    $NoMatch = Compare-Object -ReferenceObject (Get-ADGroupMember $split[0]) -DifferenceObject (Get-ADGroupMember $split[1]) | Where SideIndicator -EQ "=>"
    ForEach ($User in $NoMatch){
    Remove-ADGroupMember $split[2] -Members $User.InputObject -WhatIf -Confirm:$false
    }
    }

    • 2 år siden
  • cifwig
    Konkurranseholder
    • 2 år siden

    Would you mind to simplify your script by. using:
    $NoMatch = Compare-Object -ReferenceObject (Get-ADGroupMember "GroupA") -DifferenceObject (Get-ADGroupMember "Group0") | Where SideIndicator -EQ "=>"
    ForEach ($User in $NoMatch)
    { Remove-ADGroupMember "Group0" -Members $User -WhatIf
    }

    • 2 år siden
  • cifwig
    Konkurranseholder
    • 2 år siden

    There was no other format option for the contest. May be you can send me the ps later.

    • 2 år siden

Vis flere kommentarer Behandler...