【发布时间】:2019-03-31 06:31:48
【问题描述】:
我们在这里有一个脚本,用于显示组和组中的用户。该脚本正在运行并为我们提供输出中的信息。这是脚本:
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
}
然而,输出显示名称和 SAMAccountName 在整个脚本下方,在它说结束脚本的位置之后。我希望它显示在写着“作为 $Group 成员的用户”的写主机和 $GroupRemove = Read-Host “你想从 $Group 中删除任何人”之间
谁能告诉我在脚本中做错了什么,为什么它显示在输出的错误位置?
以下是输出供参考:
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
【问题讨论】:
-
敦促用户输入信息以供选择并不是很像 powershell。 IMO 更直观的是使用
Out-Gridview选择/标记并将其传递到管道中。
标签: powershell output