我发现this script将循环显示.csv文件并将它们合并到一个Excel工作表中。然后,我创建了第二个脚本,用以下内容调用此脚本:
echo "Combining .csv files into Excel workbook"
C:\PowerShell\ConvertCSVtoExcel.ps1
Get-ChildItem *.csv | ConvertCSV-ToExcel -output ePortalMontlyReport.xlsx
echo " "
但是当我尝试运行脚本时,我收到以下错误:
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
有关如何解决此问题的任何建议?
答案 0 :(得分:5)
You need to dot-source the .ps1 file to get the functions in it imported into your session.
. C:\PowerShell\ConvertCSVtoExcel.ps1