【发布时间】:2014-08-28 23:56:03
【问题描述】:
-问题1-
脚本:
$ADInfo = (Get-ADUser $ntaccount1 -Properties *)
Write-Host -NoNewLine -ForegroundColor Gray "Enabled ";
Write-Host -NoNewLine ": ";
if ($ADInfo.Enabled -eq "False") {'Write-Host -ForegroundColor Gray $ADInfo.Enabled'} ELSE {'Write-Host -ForegroundColor Red $ADinfo.Enabled'}; #If False=gray if True=red
输出:
Enabled: False
我正在努力做到这一点,所以如果 $ADInfo.Enabled 等于 False,则为一种颜色。如果它是真的,那就是另一个。我无法让它发挥作用。
-问题2-
我正在尝试以与问题 1 相同的格式获取此脚本,但是,我没有得到相同的输出。下面粘贴的内容 100% 有效。它会导致 AD 的到期日期。如果我试图把它变成问题 1,我会得到一些随机日期 12/31/1600 7:00:00 PM 。我希望它与问题 1 相同,因此我可以将输出日期设置为我选择的任何颜色。
Get-ADUser -identity usernamehere -properties msDS-UserPasswordExpiryTimeComputed | format-list @{ Name = "Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}};
【问题讨论】:
标签: powershell colors output