0

我想修改我的 ActiveDirectory 查找脚本以输出某个颜色的结果。

脚本导入 AD 模块,然后提示您输入用户名并查看某些属性,例如姓名、电子邮件地址和员工 ID。

我想根据输出更改几个属性的颜色。

例如,如果“LockedOut”或“PasswordExpired”为“True”,我希望这些特定结果的文本颜色为红色。

那可能吗?任何帮助是极大的赞赏!

这是脚本

Import-Module ActiveDirectory

do{ 
   $username = (read-host "Please Enter Username to Lookup")

   get-aduser $username  -properties Created, Name, EmployeeID, EmailAddress, Enabled, LockedOut, LastBadPasswordAttempt, PasswordExpired, AccountExpires, LastLogonDate, Modified, LogonCount, HomeDirectory, Office, TelephoneNumber | Format-List Created, Modified, LogonCount, Name, EmailAddress, EmployeeID, Enabled, LockedOut, PasswordExpired, LastLogonDate, LastBadPasswordAttempt, HomeDirectory, Office, TelephoneNumber

   $response = Read-Host "Enter 'Y' to check another user, any other key to exit"
   Clear-Host
}
while ($response -eq "Y") 
4

2 回答 2

2

Write-Host 具有指定前景色和背景色的参数:

Import-Module ActiveDirectory
[string[]]$getADProps=echo Created, Name, EmployeeID, EmailAddress, Enabled, LockedOut, LastBadPasswordAttempt, PasswordExpired, AccountExpires, LastLogonDate, Modified, LogonCount, HomeDirectory, Office, TelephoneNumber
[string[]]$flProps=echo Created, Modified, LogonCount, Name, EmailAddress, EmployeeID, Enabled, LockedOut, PasswordExpired, LastLogonDate, LastBadPasswordAttempt, HomeDirectory, Office, TelephoneNumber
do{ 
    $username = (read-host "Please Enter Username to Lookup")
    $adUser=Get-ADUser $username  -properties $getADProps  
    if ($adUser.'LockedOut' -or $adUser.'PasswordExpired'){
        $adUser | Format-List $flProps  | Out-String | Write-Host -ForegroundColor Red
    }
    else{
        $adUser | Format-List $flProps
    }
    $response = Read-Host "Enter 'Y' to check another user, any other key to exit"
    Clear-Host
}while ($response -eq "Y") 
于 2013-10-18T15:32:15.287 回答
1
$result = get-aduser $username  -properties Created,Name,EmployeeID,EmailAddress,`
  Enabled,LockedOut, LastBadPasswordAttempt, PasswordExpired, AccountExpires,`
  LastLogonDate,Modified, LogonCount, HomeDirectory, Office, `
  TelephoneNumber | format-list Created,Modified, LogonCount, Name, EmailAddress,`
  EmployeeID, Enabled, LockedOut,PasswordExpired, LastLogonDate,`
  LastBadPasswordAttempt,HomeDirectory, Office,TelephoneNumber |
  out-string
write-host -foregroundcolor Red $result
于 2013-10-18T15:33:28.950 回答