I would like to remove all users from 60 ADGroups and I would like to show a progress bar but have not been able to figure out how to work. How can I add a progress bar to this?
#Progress parameter
$Progress = @{
Activity = 'Counting groups in report files:'
CurrentOperation = "Loading"
Status = 'Collecting data'
PercentComplete = 0
}
Write-Progress @Progress
$i = 0
# Import CSV
$CSVFiles = Import-csv -Path "C:\CSV\Groups.csv" -Encoding Default -Delimiter ";"
Foreach($File in $CSVFiles)
{
$i++
[int]$percentage = ($i / $CSVFiles.Count)*100
$Name = $null
$Name = $file.name
$progress.CurrentOperation = "$name"
$progress.Status = 'Processing file: '
$progress.PercentComplete = $percentage
Write-Progress @Progress
#Remove all members from CSVFiles
foreach ($ADGroup in $CSVFiles) {
Get-ADGroupMember -Identity $ADGroup.Groups.Trim() | ForEach-Object {Remove-ADGroupMember $ADGroup.Groups.Trim() $_ -Confirm:$False }
}
}