Calling a specific PowerShell function from the command line

Viewed 113392

I have a PowerShell script that contains several functions. How do I invoke a specific function from the command line?

This doesn't work:

powershell -File script.ps1 -Command My-Func
5 Answers

This solution works with powershell core:

powershell -command "& { . .\validate.ps1; Validate-Parameters }" 

If it's a .psm1 file (as opposed to .ps1) then call this instead:

powershell -command "& { Import-Module <path>\script1.psm1; My-Func }"
Related