0
-Question 1-PowerShell的彩色輸出
腳本:
$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等於假,是一種顏色。如果它是真的,那麼另一個。我在解決問題時遇到了問題。
-Question 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")}};
嘿,我編輯了我的OP。 if語句不起作用(每次都將顏色更改爲綠色),並且代碼的「過期日期」位給出12/30/1600 7:00:00 PM的通用日期。我在OP中的這一行可以正常工作,但是你放它的方式不行。 – Aaron 2014-08-29 04:43:22