1
votes

I found this script that will loop through .csv files and combine them into one Excel worksheet. I then created a second script to call this one with the following:

echo "Combining .csv files into Excel workbook"
C:\PowerShell\ConvertCSVtoExcel.ps1
Get-ChildItem *.csv | ConvertCSV-ToExcel -output ePortalMontlyReport.xlsx
echo " "

But when I try to run the script, I am getting the following error:

ConvertCSV-ToExcel : The term 'ConvertCSV-ToExcel' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try
again.
At C:\PowerShell\Merge.ps1:3 char:23
+ Get-ChildItem *.csv | ConvertCSV-ToExcel -output ePortalMontlyReport. ...
+                       ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ConvertCSV-ToExcel:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Any suggestions on how to resolve this?

1

1 Answers

5
votes

You need to dot-source the .ps1 file to get the functions in it imported into your session.

. C:\PowerShell\ConvertCSVtoExcel.ps1