Freelancer: RikkaAutomate
Jaa:
Tee ilmoitus työstä

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.

Julkinen selvennystaulu

  • RikkaAutomate
    RikkaAutomate
    • 2 vuotta sitten

    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 vuotta sitten
  • cifwig
    Kilpailun järjestäjä
    • 2 vuotta sitten

    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 vuotta sitten
  • cifwig
    Kilpailun järjestäjä
    • 2 vuotta sitten

    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 vuotta sitten
  • RikkaAutomate
    RikkaAutomate
    • 2 vuotta sitten

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

    • 2 vuotta sitten
  • RikkaAutomate
    RikkaAutomate
    • 2 vuotta sitten

    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 vuotta sitten
  • RikkaAutomate
    RikkaAutomate
    • 2 vuotta sitten

    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 vuotta sitten
  • cifwig
    Kilpailun järjestäjä
    • 2 vuotta sitten

    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 vuotta sitten
  • cifwig
    Kilpailun järjestäjä
    • 2 vuotta sitten

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

    • 2 vuotta sitten

Näytä lisää kommentteja Käsitellään...