Freelancer: RikkaAutomate
Paylaşın:
Girdiyi Rapor Et

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.

Genel Açıklama Panosu

  • RikkaAutomate
    RikkaAutomate
    • 4 ay önce

    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.

    • 4 ay önce
  • cifwig
    Yarışma Sahibi
    • 4 ay önce

    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?

    • 4 ay önce
  • cifwig
    Yarışma Sahibi
    • 4 ay önce

    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.

    • 4 ay önce
  • RikkaAutomate
    RikkaAutomate
    • 4 ay önce

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

    • 4 ay önce
  • RikkaAutomate
    RikkaAutomate
    • 4 ay önce

    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

    • 4 ay önce
  • RikkaAutomate
    RikkaAutomate
    • 4 ay önce

    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
    }
    }

    • 4 ay önce
  • cifwig
    Yarışma Sahibi
    • 4 ay önce

    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
    }

    • 4 ay önce
  • cifwig
    Yarışma Sahibi
    • 4 ay önce

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

    • 4 ay önce

Daha fazla yorum göster İşleniyor...