0

-Question 1-

The script:

$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

The output:

Enabled: False

I am trying to make it, so if $ADInfo.Enabled is equal to False, be one color. And if it is True, be another. I am having problems getting that to work.

-Question 2-

I am trying to get this script in the same format as question 1, however, I don't get the same output. What is pasted below works 100%. It results an expiration date from AD. If I try to turn it into question 1, I get some random date 12/31/1600 7:00:00 PM . I want it the same as question 1, in the result that I can make the output date any color I choose.

Get-ADUser -identity usernamehere -properties msDS-UserPasswordExpiryTimeComputed | format-list @{ Name = "Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}};

1 Answer 1

1

How about this?

$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
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, I edited my OP. The if statement doesn't work (color changes to green every time), and the "Expiration Date" bit of code gives a generic date of 12/30/1600 7:00:00 PM. The line of it I have in OP works fine, but the way you put it does not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.