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

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

In PowerShell, how do I define a function in a file and call it from the PowerShell commandline?
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

Try this on the PowerShell command line:

```
. .\MyFunctions.ps1
A1

```

The dot operator is used for script include, aka "dot-sourcing" (or ["dot source notation"](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-5.1#using-dot-source-notation-with-scope))
Répondre

Revenir à « PowerShell »