Powershell - 循环脚本,直到用户选择退出

问题描述 投票:4回答:4

如何重新启动脚本?我有3个开关,我希望它们恢复到脚本的开头。

Import-Module ActiveDirectory
Write-Host "--Please Login using a.account--"
#login
$credential = Get-Credential
#Main
Write-Host "--Remote Computer Rename v2.0--"
Write-Host "1. Query AD (Outputs to a text file)"
Write-Host "2. Quick computer rename"
Write-host "3. Quit"
$choice=Read-Host "Chose a number to continue"

#AD Query for computer
switch ($choice)
{
 1 {
Write-Host "--Enter first five characters of computer name or full computer name i.e.     USCLT--"
$cn=Read-Host 'Computer name'
$out="$cn*"
Get-ADComputer -Filter 'SamAccountName -like $out' >> c:\myscripts\dsquery.txt
Write-Host "Query complete.  See dsquery.txt saved to Desktop."
}

...rest of my code.

所以看看dsquery.txt保存到桌面后。“我希望它回到写主机部分。

powershell powershell-v2.0
4个回答
0
投票

blog post我发现:

echo "Press any key to exit..."
$Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") | OUT-NULL
$Host.UI.RawUI.FlushInputbuffer()
© www.soinside.com 2019 - 2024. All rights reserved.