windows - 如何在 Powershell 中询问您是否要解锁此帐户(是/否)
问题描述
我是 powershell 的新手,我在问当你将用户信息从 AD 提取到变量 $User 后如何提示问题
例子:
$User = Read-Host -Prompt 'Input employee ID'
$LockedOut = Get-ADUser $User -Property LockedOut | foreach { $_.LockedOut }
Write-Output "Account Locked: $($LockedOut)"
帐户锁定:假
我怎么能:它应该检查帐户是否被锁定,如果是,它会提示问题你想解锁这个用户吗?(Y/N) 如果不是就提示ok
解决方案
我认为这样的事情会有所帮助:
# 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'"
}
}
推荐阅读
- android - 无法在 android 10 上创建具有已删除文件名的文件
- mstest - .net47 mstest 项目到 .net5
- node.js - Nodejs 单元测试失败时的电子邮件通知
- typescript - Redux-saga,select():“类型‘未知’不可分配给类型‘状态’”
- wordpress - 在 Microsoft Automate 中获取错误的 http 请求
- localhost - 赛普拉斯无法加载 localhost 之外的任何内容。无法使用 CDN 或 Google 字体
- google-cloud-platform - 迁移到 Google 身份和组织后如何重新获得对结算帐户的访问权限?
- vuejs3 - 如何更改 primvue 组件字体系列、字体大小和字体粗细
- java - Spring Boot 数据源不去 BeanPostProcessor 实现的 postProcessAfterInitialization 方法
- javascript - 在 ASP.NET Core 中上传图像后更改 Image 元素的 src 属性