I want to be able to isolate the date from the output of this Get-ADUser command:
Get-ADUser -identity johnd -properties LastLogonDate | Select-Object name, Last
Can you use variables? If so,
PS>$hi=Get-ADuser -identity johnd -properties LastLogonDate|select-object name,LastLogonDate
PS>$hi.LastLogonDate.ToShortDateString()
3/21/2016
PS>$hi.name
John Doe
The result of that cmdlet is an object with a set of properties. The output you see in table format is not what is literally contained in the object; it's a display representation of it.
So to first get the date object only, you can modify your Select-Object
call (which is already paring down the properties) like this:
$lastLogon = Get-ADUser -identity johnd -properties LastLogonDate |
Select-Object -ExpandProperty LastLogonDate
$lastLogon
now contains a [DateTime] object.
With that you can format it using format strings:
$lastLogon.ToString('MM/dd/yyyy')
Or even better:
$lastLogon.ToShortDateString()
(these are slightly different representations; the latter doesn't zero-pad).
The format strings give you complete control over the representation.