Back
Featured image of post Reformat the Window for PowerShell Web Access

Reformat the Window for PowerShell Web Access

I use PowerShell Web Access a lot while commuting and traveling. That comes handy, because I don’t need a working VPN and with an App (comes free from Sapien) even triggering some long-running scripts from the iPad out of a Hotel room as no longer a pain. And it doesn’t use a lot of data.

Here is a little function to tweak the web-based PowerShell window rendered by the gateway:

function Set-PSWAWindowSize
{
    <#
            .SYNOPSIS
          Reformat the Window for PowerShell Web Access

            .DESCRIPTION
          This function reformats the PowerShell Web Access windows style to fit a bit better.

            .EXAMPLE
          PS C:\> Set-PSWAWindowSize

            .NOTES
          I use PowerShell Web Access a lot while traveling. That comes handy,
          because I don't need a working VPN and with an App (comes free from
          Sapien) even triggering some long-running scripts from the iPad out of
          a Hotel room as no longer a pain. And it doesn't use a lot of data.

          Author: Joerg Hochwald - http://jhochwald.com
          This script is public domain! IT COMES WITH NO WARRANTY!

            .LINK
          https://gist.github.com/jhochwald/76950f1eef380a73bcb11cf55d0d0901

            .LINK
          https://hochwald.net/configure-windows-powershell-web-access/
  #>

	[CmdletBinding(SupportsShouldProcess = $true)]
	param ()

	if ($pscmdlet.ShouldProcess('PowerShell Window', 'Tweak it for PSWA usage'))
	{
		# Get the BufferSize
		$bufferSize = $Host.UI.RawUI.BufferSize

		# Tweak the BufferSize
		$bufferSize.Width = 180
		$Host.UI.RawUI.BufferSize = $bufferSize

		# Get the WindowSize
		$WindowSize = $Host.UI.RawUI.WindowSize

		# Tweak the WindowSize
		$WindowSize.Width = 180
		$WindowSize.Height = 40
		$Host.UI.RawUI.WindowSize = $WindowSize
	}
}

And there is a Gist for this.