关于Do的指导在PS中循环直到NULL

时间:2016-04-12 18:51:48

标签: powershell powershell-v2.0 powershell-v3.0 powershell-v4.0

大家好再次回答一些简单的问题,对于那些我们新手难以理解的专业人士。我有一个脚本,我已经完成了我的工作,基本上给了我所有锁定的终端帐户和选项,以确认解锁它们但是很难让它循环直到NULL或至少-eq 1. Can有人引导我朝着正确的方向前进吗?

######################################################################################################
# Written by CPineda
# This Script searches for all locked terminals and unlocks them accordingly 
# Last revision 04-28-2016
######################################################################################################

# Import Powershell AD Module
Import-Module activedirectory

# Search the windows terminals OU and display results
$ToSearch = "OU=ANOU,OU=ANOU,DC=DOMAIN,DC=LOCAL"
Search-ADAccount -LockedOut -SearchBase $ToSearch | Select-Object -Property Name,LockedOut,SamAccountName | Sort-Object -Property Name | Format-Table -AutoSize

# Search the windows terminals OU and display results 
$ToSearch = "OU=ANOU,OU=ANOU,DC=Domian,DC=LOCAL"
Search-ADAccount -LockedOut -SearchBase $ToSearch | Select-Object -Property Name,LockedOut,SamAccountName | Sort-Object -Property Name | Format-Table -AutoSize

# Enter the account to unlock.
Read-Host “Enter the Terminal account to unlock” | Unlock-ADAccount -Confirm -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue

# Prompt user if they want to unlock an account again
$UserInput = Read-Host -Prompt "`n`nWould you like to unlock another account (Y/n)"


  if ($UserInput -eq "Y") {

Do {

# Search the windows terminals OU and display results
$ToSearch = "OU=ANOU,OU=ANOU,DC=DOMAIN,DC=LOCAL"
Search-ADAccount -LockedOut -SearchBase $ToSearch | Select-Object -Property Name,LockedOut,SamAccountName | Sort-Object -Property Name | Format-Table -AutoSize

# Search the windows terminals OU and display results 
$ToSearch = "OU=ANOU,OU=AnOU,DC=DOMAIN01,DC=LOCAL"
Search-ADAccount -LockedOut -SearchBase $ToSearch | Select-Object -Property Name,LockedOut,SamAccountName | Sort-Object -Property Name | Format-Table -AutoSize

# Enter the account to unlock.
Read-Host “Enter the Terminal account to unlock” | Unlock-ADAccount -Confirm -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue}

Until ($UserInput -ge $null + "N")}

1 个答案:

答案 0 :(得分:0)

我在脑海中思考原始问题一英里,我试图为Null不必要的变量创建一个循环。最后,一旦我更多地考虑语法,解决方案就变得清晰了。