Try this using the -Passthrufor option Start-Processto get process information. Then we use a little pInvoke magic to move the window we just created to another location.
. X Y . Top, Left , 4 .
Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
public class pInvoke
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
}
"@
function Move-Window([System.IntPtr]$WindowHandle, [switch]$Top, [switch]$Bottom, [switch]$Left, [switch]$Right) {
$rect = New-Object RECT
[pInvoke]::GetWindowRect($WindowHandle, [ref]$rect)
$activeScreen = [System.Windows.Forms.Screen]::FromHandle($WindowHandle).Bounds
if ($Top) {
$posY = $activeScreen.Top
} elseif ($Bottom) {
$posY = $activeScreen.Bottom - ($rect.bottom - $rect.top)
} else {
$posY = $rect.top
}
if ($Left) {
$posX = $activeScreen.Left
} elseif ($Right) {
$posX = $activeScreen.Right - ($rect.right - $rect.left)
} else {
$posX = $rect.left
}
[pInvoke]::MoveWindow($app.MainWindowHandle, $posX, $posY, $rect.right - $rect.left, $rect.bottom - $rect.top, $true)
}
$app = Start-Process dotnet -ArgumentList "run" -PassThru
Move-Window -WindowHandle $app.MainWindowHandle -Bottom -Left