OpsaC - Operating as PowerShell code
published: July 7, 2019 author: Tinu tags: PowerShell categories: PowerShell-Basic
Start a PowerShell-Script with a CMD-Script, to test if there is no output in the host.
%~dp0 expands to current directory path of the running batch file. %~n0 expands to the running batch file.
@echo off
rem ---------------------------------------------------------------------------- *
rem Description: Start PS-Script
rem Author : Martin Walther
rem ---------------------------------------------------------------------------- *
rem Path: %~dp0 Script: %~n0
set log=%~dp0%~n0.log
set script=%~dp0%~n0.ps1
echo %log%
echo %script%
echo %date% %time% > %log%
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass %script% >> %log%
echo %date% %time% >> %log%
notepad %log%
pwsh.exe -File $script -ExecutionPolicy Bypass