Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Start Powershell Script

published: July 7, 2019 author: Tinu tags: PowerShell categories: PowerShell-Basic


Table of Contents

Start PowerShell over CMD

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%

Start PowerShell in a Shortcut

pwsh.exe -File $script -ExecutionPolicy Bypass

See also


← Previous Post [ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →