Fetching OU in output

This topic contains 3 replies, has 3 voices, and was last updated by  Wilm Reiche 3 months, 3 weeks ago.

  • Author
    Posts
  • #73847

    Venky
    Participant

    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

  • #73852

    Don Jones
    Keymaster

    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

    Venky
    Participant

    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

    Wilm Reiche
    Participant

    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.