Hi
im trying to delete Groups that contain special names. What im trying to do is to check first if there are such Groups and then pipe the deletion into the get-adgroup. If there are no Groups found it exit (i dont want the script to go through the deletion
part). I cant get the foreach loop to be piped after get-adgroup. any help will be appreciated.
#Remove Active Directory groups
$Server = "SERVER01"
$X = Adminitrator_' + $Server + '*'
try
{
Get-ADGroup -Filter {Name -like $X} | Select-Object Name -ErrorAction Stop | foreach ($ADGroup in $ADGroups)
{
Write-Host $ADGroup.Name
#Remove-ADGroup -Identity $ADGroup.Name
}
}
catch
{
"the following error appeared: `"$($_.Exception.Message)`""
}