i am the funny
 

 I AM THE FUNNY!!!

So, have you ever created a security group to lock down a folder on a file server, but the server is out in woop woop and you need to wait for the group to replicate to the local domain controller so that you can apply permissions? ... No? ... well, I have. And it is annoying waiting for it to occur and easy to forget.

Anyway, this will loop through and keep checking until the groups exist or it reaches 100 loops. It will also tell you when all of the groups exist.

Import-Module ActiveDirectory

$grouplist = @()

$grouplist = "group1","group2","group3"

# Getting the number of groups you have put in
$numberGroups = $grouplist.Count

# Server that you want to check
$server = "PINKENBA1DC.lands.resnet.qg"

[Reflection.Assembly]::LoadWithPartialName('System.Speech') | Out-Null 
$object = New-Object System.Speech.Synthesis.SpeechSynthesizer 

$x=0

# This is set up to loop through 100 times, or until all groups exist
do {
    cls
    # this is the counter so can auto exit once the groups all exist
    $countingGroups=0
    $x++
    write-host "Search $x of 100`n"
    foreach($group in $grouplist){
        # checks to see if the user exists checking CN
        $b = Get-ADGroup -ldapfilter "(&(ObjectCategory=Group)(cn=$group))" -Server $server
        if ($b -eq $null){
            write-host "Group $group is not on this server." -ForegroundColor Red
        }Else{
            write-host "Group $group is now present on the server." -ForegroundColor Green
            # Counting number of groups that exist
            $countingGroups++
        } 
    }

    # Sets x to 100 so that it exits if all groups exist
    If($countingGroups -eq $numberGroups){
        $x=100
        Write-host "`nAll groups synced to this server.`n`nExiting now."
        $object.Speak("All Groups Exist")
        start-sleep 2
    }Else{
        Start-Sleep -Seconds 30
    }
 }until($x -eq 100)

 Pause