Hi
Trying to run the last logon script, it works fine with the output showing computer-names, date and time. But it does not show the OU path of the those computers in the output file.
How can fetch the AD OU path?
Thanks
Venky
Hi
Trying to run the last logon script, it works fine with the output showing computer-names, date and time. But it does not show the OU path of the those computers in the output file.
How can fetch the AD OU path?
Thanks
Venky
I’ve no idea what you’re talking about, sorry.
Do you mean, “how can I find out which OU a computer is in, if I know the computer name?”
import-module activedirectory
$domain = “mydom.com”
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
$OU =“OU=Max,DC=mydom,DC=com”
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -SearchBase $OU -Properties LastLogonTimeStamp |
select-object Name,@{Name=“Stamp”; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}| export-csv OLD_Computer.csv -notypeinformation
in output file need OU path to show.
I guess the easiest way would simply be to output the distinguished name of the computer. You could strip away the CN=* and have the LDAP path as the result.