WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bettman on August 19, 2023, 03:00:53 PM

Title: Calling a function within a Powershell Script
Post by: bettman on August 19, 2023, 03:00:53 PM
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.
Title: Re: Calling a function within a Powershell Script
Post by: td on August 19, 2023, 07:35:19 PM
There are multiple ways to properly escape the parameter line. Here is but one:

Code (winbatch) Select
str = "-executionpolicy bypass-command ""& { .'%%~dp0Install_App.ps1'; UninstallApp }"""
Message("Escaped Line", str)
exit




Title: Re: Calling a function within a Powershell Script
Post by: td on August 21, 2023, 07:08:41 AM
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 }"""