I am working on a script to apply a specific retention policy to individuals who are members of a particular group, another for rooms, and yet another to everyone else. Below is what I'm working with:
I run into an error that states "Pipeline not executed because a pipeline is already executing..." and the retention policy doesn't get set. can someone tell me where I've gone wrong here? Or perhaps an easier solution?
#Check entire domain
Set-ADServerSettings -ViewEntireForest $true
#Active Directory Group
$Group = [ADSI]("LDAP://CN=EXCHANGE_DISABLE_PURGE,OU=EXCHANGE ACCOUNTS,DC=domain,dc=com")
#Enum Group Members and set equal to array
$Grouplist = $Group.member
#do loop varaible setup
$GroupLength=$Grouplist.count
$GroupArrayLength=$GroupLength - 1
$GroupCount = 0
$Userlist= @(0..$GroupArrayLength)
$UsersDN=@(0..$GroupArrayLength)
#do loop to disable purge policy for all array members
do {
$Userlist[$GroupCount] = [ADSI]("LDAP://" + $Grouplist[$GroupCount])
$UsersDN[$GroupCount] = $userlist[$GroupCount].distinguishedname
$GroupLength=$GroupLength - 1
$GroupCount++
}
until ($GroupLength -eq 0)
Get-mailbox -database db01 -resultsize Unlimited | foreach-object{
if ([string[]]$UsersDN -contains $_.DistinguishedName){
if ($_.RetentionPolicy -ne "NoPurge"){
set-mailbox $_ -RetentionPolicy NoPurge
write-host("Applied - No Purge Policy to "+$_.DisplayName) -ForeGroundColor Green
}
}
elseif (($_.RecipientTypeDetails -eq "RoomMailBox") -or ($_.RecipientTypeDetails -eq "EquipmentMailbox")){
if ($_.RetentionPolicy -ne "Default Resource/Equipment Policy"){
set-mailbox -identity $_ -RetentionPolicy "Default Resource/Equipment Policy"
write-host("Applied - Default Resource/Equipment Policy to "+$_.DisplayName) -ForeGroundColor Green
}
}
else{
if ($_.RetentionPolicy -ne "180DayDefault"){
set-mailbox -identity $_ -RetentionPolicy "180DayDefault"
write-host("Applied - Default 180 Day Purge Policy to "+$_.DisplayName) -ForeGroundColor Green
}
}
}