Question:
I would like to know how to call a powershell function using a .Bat file.
I have this simple function:
(Script.ps1)
1 2 3 4 5 |
function testfunction { Write-Log "Calling from Bat file" } |
and I would like to call the function testfunction within the .Bat File.
powershell .\Script.ps1 …
Answer:
I noticed that there is a switch -ExecutionPolicy ByPass
which allows the batch file to run using Powershell. This works here, taken from the answer by vonPryz.
1 2 3 4 5 6 7 |
@echo off :: Create a test script file echo function test { write-host "Called from %~f0" } > s.ps1 powershell -ExecutionPolicy ByPass -command ". "%cd%\s.ps1"; test;" del s.ps1 pause |