Powershell ps1 file “is not recognized as a cmdlet, function, operable program, or script file.”

前端 未结 3 2009
你的背包
你的背包 2020-12-11 14:36

I made a Powershell function just now and saved it to a ps1 file. However, when I try to execute it from within powershell, it won\'t run.

I\'ve allready changed to

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 15:23

    This is a typical error across many platforms where your environment path does not include your current directory. so when you execute your script (or command or program etc), your runtime environment looks everywhere except your current/working directory.

    Try

    PS> .\listAllPaths.ps1 c:\ *.pdf testingPDF.txt
    

    EDIT: After reading your comments, I'm going to suggest you try this. I haven't actually verified the logic of your PS script. I'm merely trying to get your script to execute first.

    Try editing your script as below, and execute as above.

    Function listAllPaths([string]$fromFolder, [string]$filter, [string]$printfile){
    Get-ChildItem -Path $fromFolder -Include $filter -Recurse -Force -Name > $printfile
    }
    
    listAllPaths
    

提交回复
热议问题