locked
Powershell command to get list of computers and OU RRS feed

  • Question

  • Hi guys,

    I need to have an output in Powershell or maybe a report in AD to display list of computers, its OU, OS and lastlogontimestamp.

    output should be this:

    ComputerName |   OU  | OS  | Lastlogontimestamp

    Can anyone please help me on this one?

    Thank you!


    Thursday, January 29, 2015 5:32 AM

Answers

  • Not really a script needed for this unless you want the output to be used for some other script.

    Using Quest powershell it could be like this:

    Get-QADComputer -IncludedProperties lastLogonTimestamp | ft -AutoSize Name,ParentContainer,lastLogonTimestamp,operatingSystem

    of course you can redirect the output to csv

     > c:\pss\PClist.csv

    • Marked as answer by whitesql Friday, January 30, 2015 3:08 AM
    Thursday, January 29, 2015 6:28 AM
  • get-adcomputer -filter * -properties operatingsystem,lastlogontimestamp |select name,operatingsystem,@{n=’OUPath’;e={$_.distinguishedName -replace '^.+?,(CN|OU.+)’,’$1'}},@{n="lastlogon";e={[datetime]::FromFileTime($($_.LastLogonTimeStamp))}}

    • Proposed as answer by Mekac Thursday, January 29, 2015 3:12 PM
    • Marked as answer by whitesql Friday, January 30, 2015 3:08 AM
    Thursday, January 29, 2015 7:53 AM

All replies

  • Hi,

    This powershell one line query may help you to get info:

    Get-ADComputer -Filter * -Properties * | select samaccountname,canonicalname,operatingSystem,lastLogonTimestamp

    Regards

    Irfan Ahmed

    Thursday, January 29, 2015 6:21 AM
  • Not really a script needed for this unless you want the output to be used for some other script.

    Using Quest powershell it could be like this:

    Get-QADComputer -IncludedProperties lastLogonTimestamp | ft -AutoSize Name,ParentContainer,lastLogonTimestamp,operatingSystem

    of course you can redirect the output to csv

     > c:\pss\PClist.csv

    • Marked as answer by whitesql Friday, January 30, 2015 3:08 AM
    Thursday, January 29, 2015 6:28 AM
  • get-adcomputer -filter * -properties operatingsystem,lastlogontimestamp |select name,operatingsystem,@{n=’OUPath’;e={$_.distinguishedName -replace '^.+?,(CN|OU.+)’,’$1'}},@{n="lastlogon";e={[datetime]::FromFileTime($($_.LastLogonTimeStamp))}}

    • Proposed as answer by Mekac Thursday, January 29, 2015 3:12 PM
    • Marked as answer by whitesql Friday, January 30, 2015 3:08 AM
    Thursday, January 29, 2015 7:53 AM
  • Thank you very much!!

    You guys are awesome!!

    Friday, January 30, 2015 3:09 AM