question

Stormls200-1036 avatar image
0 Votes"
Stormls200-1036 asked Stormls200-1036 commented

Powershell 5.1.17763.1490 export-csv exporting blank document

I am working my way through a few PowerShell courses but clearly still need assistance. When I run the minor script below it works as it should by displaying which computers in the OU are down. No issue with that but Export-CSV is coming up with no data at all. I have read the help for Export-CSV and didn't see (or missed it) showing any issues with using % when exporting to CSV. Any help along with an explanation would be helpful.

get-adcomputer -Filter -SearchBase "OU=MedDispenseInterface,OU=MedDispense,OU=Computer Accounts,DC=select,DC=corp,DC=sem" -Properties | Select Name, LastLogondate | foreach { if (test-connection $ -quiet) { $Null } else {write-host "$ is down" -foregroundcolor RED}} | Export-Csv -LiteralPath C:\Users\lamsthomas\Desktop\MD.csv





windows-server-powershell
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please post your code as Code Sample (Ctrl. + K).

Reading your code will be much easer and no code characters are deleted by the Q&A editor.

Thanks you.


Kind regards
Andreas Baumgarten

0 Votes 0 ·

Thank you!

0 Votes 0 ·

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered Stormls200-1036 commented

Hi,

You have to pass the ADComputer objects to the Export-Csv cmdlet.

 Get-ADComputer -Filter * -SearchBase "OU=MedDispenseInterface,OU=MedDispense,OU=Computer Accounts,DC=select,DC=corp,DC=sem" -Properties * | 
     Select-Object Name, LastLogondate | ForEach-Object { 
         if (Test-Connection $ -Quiet) { $Null } 
         else {
             Write-Host "$_ is down" -ForegroundColor RED
             $_
         }} | 
     Export-Csv -LiteralPath C:\Users\lamsthomas\Desktop\MD.csv

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the assistance!

0 Votes 0 ·