In PowerShell, how do I define a function in a file and call it from the PowerShell commandline?

前端 未结 7 1391
悲&欢浪女
悲&欢浪女 2020-12-12 08:29

I have a .ps1 file in which I want to define custom functions.

Imagine the file is called MyFunctions.ps1, and the content is as follows:

Write-Host          


        
7条回答
  •  不思量自难忘°
    2020-12-12 09:18

    . "$PSScriptRoot\MyFunctions.ps1" MyA1Func

    Availalbe starting in v3, before that see How can I get the file system location of a PowerShell script?. It is VERY common.

    P.S. I don't subscribe to the 'everything is a module' rule. My scripts are used by other developers out of GIT, so I don't like to put stuff in specific a place or modify system environment variables before my script will run. It's just a script (or two, or three).

提交回复
热议问题