Powershell change directory and run command
New to PS.
I'm trying to run a script that gets the current path, opens a new PS window from a subdirectory and leaves the PS window open, and runs a command from there.
The command varies, my example just uses write-ouput, but it would be something more like "dotnet watch"
Something like this:
$dir = $PSScriptRoot
$folder = '\MyFolder'
$subdir = "$dir$folder"
$message = "hello world"
$process = Start-Process powershell.exe ("-noexit " + "cd $subdir" + "Write-output $message")
This runs without error, but of course it opens 2 PS windows, I'm wanting to do this all from one.
$dir = $PSScriptRoot
$folder = '\MyFolder'
$subdir = "$dir$folder"
$message = "hello world"
$process = Start-Process powershell.exe ("-noexit " + "cd $subdir")
$process = Start-Process powershell.exe ("-noexit " + "Write-output $message")
Comments
Post a Comment