- 问题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")}};
答案 0 :(得分:1)
这个怎么样?
$ADInfo = (Get-ADUser jdoe -Properties *)
Write-Host "Full Name : " $ADinfo.Name
Write-Host "User ID : " $ADinfo.SamAccountName
Write-Host "Email : " $ADinfo.mail
Write-Host "Enabled : " $ADInfo.Enabled
Write-Host "Locked Out : " -NoNewline; if ($ADInfo) {Write-Host -ForegroundColor Green $ADInfo.LockedOut} ELSE {Write-Host -ForegroundColor Red $ADinfo.LockedOut}
Write-Host "Expiration Date : " -NoNewline; Write-Host ([datetime]::FromFileTime($ADInfo."msDS-UserPasswordExpiryTimeComputed"))
Write-Host "Password Last Set : " $ADinfo.PasswordLastSet
Write-Host "Last Bad Password Attempt : " $ADinfo.LastBadPasswordAttempt
Write-Host "Account Creation Date : " $ADinfo.whenCreated
Write-Host "Last change : " $ADinfo.whenChanged
Write-Host "Employee ID : " $ADinfo.EmployeeID
Write-Host "Account Description : " $ADinfo.Description