Fetching OU in output

Welcome Forums General PowerShell Q&A Fetching OU in output

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 10 months ago.

  • Author
  • #73847

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member


    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    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

    Topics: 0
    Replies: 6
    Points: 0
    Rank: Member

    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.

The topic ‘Fetching OU in output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort