【问题标题】:How to ask do you wan to unlock this account in Powershell (Yes/No) [duplicate]如何询问您是否要在 Powershell 中解锁此帐户(是/否)[重复]
【发布时间】:2018-12-19 11:07:30
【问题描述】:
我是 powershell 新手,我想问的是,当您将用户信息从 AD 提取到变量 $User 后如何提示问题
示例:
$User = Read-Host -Prompt 'Input employee ID'
$LockedOut = Get-ADUser $User -Property LockedOut | foreach { $_.LockedOut }
Write-Output "Account Locked: $($LockedOut)"
帐户锁定:错误
我如何能够:
它应该检查帐户是否被锁定,如果是,则会提示问题您要解锁此用户吗? (是/否)
如果不是它只是提示ok
【问题讨论】:
标签:
windows
powershell
active-directory
【解决方案1】:
我认为这样的事情会有所帮助:
# get the employeeID from user input. This will return a string; not a ADUser object
$empID = Read-Host -Prompt 'Input employee ID'
if (-not [string]::IsNullOrWhiteSpace($empID)) {
# try and find the user having property 'EmployeeID' set to $empID
$user = Get-ADUser -Filter "EmployeeID -eq '$empID'" -Properties LockedOut, DisplayName
if ($user) {
# if we found the user and he/she is locked out
if ($user.LockedOut) {
$action = Read-Host -Prompt "Would you like to unlock user $($user.DisplayName)? (Y/N)"
if ($action -eq 'Y') {
$user | Unlock-ADAccount -Confirm:$false
}
}
else {
Write-Host "User $($user.DisplayName) is not locked out" -ForegroundColor Green
}
}
else {
Write-Warning "Could not find user with EmplyeeID '$empID'"
}
}