locked
Help with a command? RRS feed

  • Question

  • I get a .csv file export from my security office that has a list of computer host names in column A, and a list of applications that require my attention (Updates usually). 

    I'd like a powershell command to look at the CSV file column A, then take those computer names and provide me a new .CSV file that shows the computer names along with the computer description, computer name and last login.

    I have the following, but I know it's wrong. What I think it's doing is ignoring my CSV file and running the command against every PC in the domain....

    Import-Csv -Path C:\Script\CName.csv | Get-ADComputer -Filter * -Properties *  | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\script\Export.csv

    Friday, July 5, 2019 5:19 PM

All replies

  • Change your -Filter from "*" to "Name -like $_.ComputerName*" (assuming the computer names are in a column named "ComputerName", of course).

    Then:

    Import-Csv -Path C:\Script\CName.csv | 
      Foreach {
        Get-ADComputer -Filter "Name -like $_.ComputerName*" -Properties *
      } | Sort LastLogonDate | 
          Select Name, LastLogonDate |
          Export-Csv C:\script\Export.csv -NoTypeInfo


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)



    Friday, July 5, 2019 5:46 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, July 8, 2019 2:59 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee



    Just do it.

    Wednesday, July 31, 2019 8:29 AM