I find that often the bottom of a new console is pushed off the bottom of the screen so I put the below into my $Profile to fix that. I have tried to start using the new Windows Terminal for PowerShell work and have discovered that none of the console resizing tools that I use like this function. While this makes sense (as it is not a PowerShell console!), people are obviously going to want workarounds for this when using Windows Terminal (and I find the same problem that new Windows Terminals are often partly of the bottom of the screen).
Has anyone found workarounds for $host.UI.RawUI.
that we can use to resize/move the new Windows Terminal app?
function Global:Set-ConsoleTopLeft {
# Note: the DLL code below should NOT be indented from the left-side(!)
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int W, int H); '
$consoleHWND = [Console.Window]::GetConsoleWindow();
$consoleHWND = [Console.Window]::MoveWindow($consoleHWND,75,0,600,600);
# $consoleHWND = [Console.Window]::MoveWindow($consoleHWND,-6,0,600,600);
}
function Global:Set-MaxWindowSize {
if ($Host.Name -match "console") {
$MaxHeight = $host.UI.RawUI.MaxPhysicalWindowSize.Height - 1
$MaxWidth = $host.UI.RawUI.MaxPhysicalWindowSize.Width - 20
$MyBuffer = $Host.UI.RawUI.BufferSize
$MyWindow = $Host.UI.RawUI.WindowSize
$MyWindow.Height = ($MaxHeight)
$MyWindow.Width = ($Maxwidth-2)
$MyBuffer.Height = (9999)
$MyBuffer.Width = ($Maxwidth-2)
$host.UI.RawUI.set_bufferSize($MyBuffer)
$host.UI.RawUI.set_windowSize($MyWindow)
}
}
Set-ConsoleTopLeft
Set-MaxWindowSize