SOLVED

Cannot Export to CSV when using Select-Object

%3CLINGO-SUB%20id%3D%22lingo-sub-1209247%22%20slang%3D%22en-US%22%3ECannot%20Export%20to%20CSV%20when%20using%20Select-Object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1209247%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20having%20an%20issue%20with%20exporting%20results%20from%20Powershell%20to%20a%20CSV%20file.%20When%20I%20run%20the%20command%20without%20the%20select-object%20option%20I%20get%20a%20csv%20fle%20that%20has%20way%20too%20much%20info%20in%20it.%20But%20when%20I%20try%20and%20pipe%20the%20export-csv%20to%20the%20end%20of%20the%20command%20I%20get%20an%20error.%20I%20am%20sure%20there%20is%20a%20simple%20explanation%20but%20I%20am%20fairly%20new%20to%20Power%20Shell%20and%20all%20the%20searching%20I%20have%20done%20is%20getting%20me%20nowhere%20any%20help%20is%20greatly%20appreciated.%20The%20command%20is%20below....%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EThis%20command%20returns%20the%20filtered%20results%20I%20am%20looking%20for%20in%20the%20Powershell%20window%20but%20I%20want%20this%20info%20exported%20to%20.csv%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-MsolUser%20-All%20%7C%20Where-Object%20%7B(%24_.licenses).AccountSkuId%20-match%20%22MCOMEETADV%22%20%20%7D%20%7C%20select-object%20Displayname%2COffice%2CState%2CCity%2CUsageLocation%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EThis%20result%20runs%20fine%20too%20but%20it%20exports%20WAY%20too%20much%20info%20in%20the%20.csv%20file%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-MsolUser%20-All%20%7C%20Where-Object%20%7B(%24_.licenses).AccountSkuId%20-match%20%22MCOMEETADV%22%20%20%7D%20%7C%20Export-Csv%20%22C%3A%5Ctemp%5CSkypeConferenceUsers.csv%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ECombining%20the%20two%20in%20the%20below%20snipit%20give%20me%20an%20error%20and%20wont%20run.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-MsolUser%20-All%20%7C%20Where-Object%20%7B(%24_.licenses).AccountSkuId%20-match%20%22MCOMEETADV%22%20%20%7D%20%7C%20select-object%20Displayname%2COffice%2CState%2CCity%2CUsageLocation%20%7C%20Export-Csv%20%22C%3A%5Ctemp%5CSkypeConferenceUsers.csv%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1209247%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1209353%22%20slang%3D%22en-US%22%3ERe%3A%20Cannot%20Export%20to%20CSV%20when%20using%20Select-Object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1209353%22%20slang%3D%22en-US%22%3E%3CP%3EI%20don't%20see%20any%20problems%20with%20it%2C%20what%20is%20the%20error%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1209565%22%20slang%3D%22en-US%22%3ERe%3A%20Cannot%20Export%20to%20CSV%20when%20using%20Select-Object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1209565%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20reply%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3BOddly%20enough%20it%20does%20work.%20I%20was%20battling%20with%20this%20all%20morning%20and%20it%20may%20have%20been%20a%20typo%20somewhere%20but%20it%20is%20working%20now.%20I%20appreciate%20you%20looking%20at%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I am having an issue with exporting results from Powershell to a CSV file. When I run the command without the select-object option I get a csv fle that has way too much info in it. But when I try and pipe the export-csv to the end of the command I get an error. I am sure there is a simple explanation but I am fairly new to Power Shell and all the searching I have done is getting me nowhere any help is greatly appreciated. The command is below....

This command returns the filtered results I am looking for in the Powershell window but I want this info exported to .csv

 

 

Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match "MCOMEETADV"  } | select-object Displayname,Office,State,City,UsageLocation

 

 

This result runs fine too but it exports WAY too much info in the .csv file

 

 

Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match "MCOMEETADV"  } | Export-Csv "C:\temp\SkypeConferenceUsers.csv"

 

 

Combining the two in the below snipit give me an error and wont run.

 

 

Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match "MCOMEETADV"  } | select-object Displayname,Office,State,City,UsageLocation | Export-Csv "C:\temp\SkypeConferenceUsers.csv"

 

 

 

2 Replies
Best Response confirmed by charlie4872 (Contributor)
Solution

I don't see any problems with it, what is the error?

Thanks for the reply@Vasil Michev Oddly enough it does work. I was battling with this all morning and it may have been a typo somewhere but it is working now. I appreciate you looking at it.