All Things WinBatch > WinBatch
Calling a function within a Powershell Script
(1/1)
bettman:
Greetings,
I have a powershell script which contains various functions, one of which is used to uninstall software. The command line to invoke this from a DOS batch file is as follows:
powershell.exe -executionpolicy bypass-command "& { .'%~dp0Install_App.ps1'; UninstallApp }"
I have looked for a Winbatch example which describes how to do this but could not find one. I then thought of just invoking Powershell using Runwait (or something similar) but could not figure out how to format the bolded string section so Winbatch would accept it.
Any help would be appreciated.
td:
There are multiple ways to properly escape the parameter line. Here is but one:
--- Code: Winbatch ---str = "-executionpolicy bypass-command ""& { .'%%~dp0Install_App.ps1'; UninstallApp }"""
Message("Escaped Line", str)
exit
td:
A bug in the forum's WinBatch Script rendering extension converts single quotes to their HTML equivalent so the the ' sequence is actually a single quote. It should be the following:
"-executionpolicy bypass-command ""& { .'%%~dp0Install_App.ps1'; UninstallApp }"""
Navigation
[0] Message Index
Go to full version