Reputation: 107
I have a small Powershell script that I run to show HR the status of a terminated user account. Is there a way to have the color change from the default to RED if the LastLogonDate exceeds the time of the ModifiedDate?
Get-ADUser $User1 -Properties Name, Enabled, UserPrincipalName, LastLogonDate, Modified | Select Name, Enabled, UserPrincipalName, LastLogonDate, Modified
I'm not married to the code, so if there's a better way to do this, I'm interested in knowing more.
Upvotes: 1
Views: 523
Reputation: 46
The issue is you are working with a table.
You can change the whole table red or just add a warning in red.
I would just put a warning in red.
$table=Get-ADUser $User1 -Properties Name, Enabled, UserPrincipalName, LastLogonDate, Modified | Select Name, Enabled, UserPrincipalName, LastLogonDate, Modified
$orginal=[console]::ForegroundColor
if ( $table.LastLogonDate -gt $table.Modified) {
Write-Host -ForegroundColor Red "Warning! - Put info here!"
}
If you wanted to change the whole console color and change it back it is an option
$table=Get-ADUser $User1 -Properties Name, Enabled, UserPrincipalName, LastLogonDate, Modified | Select Name, Enabled, UserPrincipalName, LastLogonDate, Modified
$orginal=[console]::ForegroundColor
if ( $table.LastLogonDate -gt $table.Modified) {
Write-Host -ForegroundColor Yellow "Warning! - Put info here!"
[console]::ForegroundColor = "Red"
$table
[console]::ForegroundColor = $orginal
} else {
$table
}
Upvotes: 2