Fetching OU in output

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Wilm Reiche Wilm Reiche 4 weeks, 1 day ago.

  • Author
  • #73847
    Profile photo of Venky


    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?


  • #73852
    Profile photo of Don Jones
    Don Jones

    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?"

  • #73855
    Profile photo of Venky

    import-module activedirectory
    $domain = "mydom.com"
    $DaysInactive = 90
    $time = (Get-Date).Adddays(-($DaysInactive))
    $OU ="OU=Max,DC=mydom,DC=com"

    # Get all AD computers with lastLogonTimestamp less than our time
    Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -SearchBase $OU -Properties LastLogonTimeStamp |

    # Output hostname and lastLogonTimestamp into CSV
    select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}| export-csv OLD_Computer.csv -notypeinformation

    in output file need OU path to show.

  • #73883
    Profile photo of Wilm Reiche
    Wilm Reiche

    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.

You must be logged in to reply to this topic.