Unable to Export-CSV and Export-Excel with file $path

%3CLINGO-SUB%20id%3D%22lingo-sub-1066513%22%20slang%3D%22en-US%22%3EUnable%20to%20Export-CSV%20and%20Export-Excel%20with%20file%20%24path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1066513%22%20slang%3D%22en-US%22%3E%3CP%3EUnable%20to%20Export-CSV%20%26amp%3B%20Export-Excel%20with%20file%20%24path%26nbsp%3B%20%26nbsp%3Bplease%20help%20me%20on%20this.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAble%20to%20export%20with%20full%20path%20Export-excel%20%22c%3A%5C123%5Ctest.xlsx%22%3C%2FP%3E%3CP%3EBut%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20able%20to%20export%20with%20below%3C%2FP%3E%3CP%3E%24path%20%3D%20c%3A%5C123%5Ctest.xlsx%3C%2FP%3E%3CP%3EExport-excel%20%24path%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20not%20open%20Excel%20Package%20c%3A%5C123%5Ctest.xlsx%3CBR%20%2F%3EAt%20C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CImportExcel%5C6.1.0%5CExport-Excel.ps1%3A546%20char%3A16%3CBR%20%2F%3E%2B%20catch%20%7Bthrow%20%22Could%20not%20open%20Excel%20Package%20%24path%22%7D%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20OperationStopped%3A%20(Could%20not%20open%20...123.xlsx%3AString)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20Could%20not%20open%20Excel%20Package%20c%3A%5C123%5Ctest.xlsx%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1066513%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1081522%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20Export-CSV%20and%20Export-Excel%20with%20file%20%24path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1081522%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F488810%22%20target%3D%22_blank%22%3E%40Rahaman_Syed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24f%20%3D%20'D%3A%5CTemp%5Clist.csv'%0AGet-Service%20%7C%20Export-Csv%20-Path%20%24f%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

Unable to Export-CSV & Export-Excel with file $path   please help me on this. 

 

Able to export with full path Export-excel "c:\123\test.xlsx"

But 

 

Not able to export with below

$path = c:\123\test.xlsx

Export-excel $path 

 

Could not open Excel Package c:\123\test.xlsx
At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\6.1.0\Export-Excel.ps1:546 char:16
+ catch {throw "Could not open Excel Package $path"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Could not open ...123.xlsx:String) [], RuntimeException
+ FullyQualifiedErrorId : Could not open Excel Package c:\123\test.xlsx

1 Reply
Highlighted

@Rahaman_Syed 

$f = 'D:\Temp\list.csv'
Get-Service | Export-Csv -Path $f