Powershell颜色输出
-问题1- 剧本:Powershell颜色输出,powershell,colors,output,Powershell,Colors,Output,-问题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
$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")}};
这个怎么样
$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
嘿,我编辑了我的OP。if语句不起作用(每次颜色都变为绿色),代码中的“过期日期”位给出的通用日期是12/30/1600 7:00:00 PM。我在OP里的那一行很好,但你说的方式不行。