Hi I'm trying to create a script that will check if the list of AD Group I provided exist in AD but the script only returns the last object it found. Please disregard the previous sample code and refer to this one. The script seems to run but it is not returning all the ADGroup in the list even if they all exist as confirmed manually. It only returns the last object.
function CheckAD
{
$AD= "AA","BB"
foreach ($group in $AD)
{
$R_AD= @()
$R_AD=Get-ADGroup -filter {GroupCategory -eq "Security" -and Name -eq $group} -SearchBase "OU=Application,OU=SOO,OU=Groups,OU=UN,DC=B3,DC=in"|select -ExpandProperty name -Unique
if ($R_AD.count -gt 0)
{
$r = New-Object -TypeName psobject
$r|Add-Member -MemberType NoteProperty -Name ADGroup -Value $R_AD
}
}
return($r)
}
$Test=CheckAD