we've got a script here what we're using to display groups and then the users who are in the groups. The script is working and getting us the information in the output. Here is the script:
Clear-Host
Write-Host "Group Query & Edit Tool." -ForegroundColor Yellow
Start-Sleep -Seconds 2
Start-Process "\\capeplc.net\IT-GroupData\Onsite Group Memberships\GBSSOnsiteGroupList.txt"
$Group = Read-Host "Enter the name of the group you require memberships pulling from"
Write-Host " "
Write-Host "Users who are members of $Group :"
Get-ADGroupMember -Identity $Group | Select Name,SAMAccountName -Wait
Start-Sleep -Seconds 1
$GroupRemove = Read-Host "Do you want to remove anyone from $Group ?"
if ($GroupRemove -eq "Y"){
$User = Read-Host "Enter the username of the user who needs removing
(SAMAccountName)"
Remove-ADGroupMember -Identity $Group -Members $User
}
else {
Write-Host "Ending script..."
exit
}
The output however displays the Name & SAMAccountName underneath the entire script after where it says ending script. I want this to display between the write-host which says "Users who are members of $Group" and the $GroupRemove = Read-Host "Do you want to remove anyone from $Group"
Can anyone advise what I'm doing wrong in the script for why it's displaying in the wrong place in the output?
Here is the output for reference:
Group Query & Edit Tool.
Enter the name of the group you require memberships pulling from: GBSS-Onsite-Admin-Aldborough
Users who are members of GBSS-Onsite-Admin-Aldborough :
Do you want to remove anyone from GBSS-Onsite-Admin-Aldborough ?: N
Ending script...
Name SAMAccountName
---- --------------
Test User Test.User