我们这里有一个脚本,用于显示组,然后显示组中的用户。该脚本正在运行,并向我们提供了输出中的信息。这是脚本:
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 =读主机“是否要从$ 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
答案 0 :(得分:0)
powershell对于发送到标准输出的任何内容都有内置的延迟。 Write-Host
转到主机,而不是标准输出。因此,如果显示系统认为途中可能会有更多相同类型的对象,则可能会导致延迟。我认为延迟是300毫秒,但我不确定。
解决方法是执行以下操作之一...
| Out-Host
,以强制该项目到主机,而无需通过显示系统延迟例程