0

I need to export the result to CSV. Can someone guide me on how to do it

$Inventory = Get-Content -Path 'C:\Users\tdadmin\Desktop\hostname.txt'
foreach ($computer in $Inventory) {
    Get-ADComputer -Identity $computer -Properties * | FT Name, LastLogonDate -Autosize
}
1
  • Export-CSV ... read the help including the examples please. Commented Dec 19, 2018 at 23:40

1 Answer 1

4

Do not use Format-* cmdlets unless you want to present data directly to a user. For selecting particular properties of your input objects use Select-Object. Use a pipeline and remove the loop (Get-ADComputer accepts pipeline input). Use Export-Csv for actually exporting the data to a CSV.

Get-Content -Path 'C:\Users\tdadmin\Desktop\hostname.txt' |
    Get-ADComputer -Properties * |
    Select-Object Name, LastLogonDate |
    Export-Csv 'C:\path\to\output.csv -NoType
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.