Controlling window position of a Powershell console

This works:

(Get-Host).UI.RawUI $a = (Get-Host).UI.RawUI $a.BackgroundColor = "white" $a.ForegroundColor = "black" $size = (Get-Host).UI.RawUI.WindowSize $size.Width = 80 $size.Height = 30 (Get-Host).UI.RawUI.WindowSize = $size

But this doesn't work, and I am not sure how to make it work:

$position = (Get-Host).UI.RawUI.Windowposition $position.X = 0 $position.Y = 30 (Get-Host).UI.RawUI.Windowposition = $position

The error I get is strange. It complains about "buffer" when I am trying to set external window position:

Exception setting "WindowPosition": "Cannot use the specified Window X (column) position because it extends past the width of the screen buffer. Specify another X position, starting with 0 as the left most column of the buffer.

-------------Problems Reply------------

The error is not really strange, because WindowPosition Gets and sets the position, in characters, of the view window relative to the screen buffer.

It does not set the position of the Window, but to put it crudely, the position in the buffer that you see through the view of the window. So in your case, you are getting the error because it is outside the buffer.

Unfortunately, setting the position of the window is not simple. There is a snapin for it though - ( use Set-WindowPosition)

Take a look at this script: Resize-Console.ps1 – Resize console window/buffer using arrow keys.

It is hopefully useful itself and partially should answer the question (the size part).

Category:powershell Views:1 Time:2011-09-29

Related post

  • Powershell console control 2012-01-24

    Does anybody know of a console control that I can use to host a Powershell console in my WPF app? I have a WPF app that is scriptable with Powershell, and I want to allow the user to open up a PS console to type some commands. --------------Solutions

  • C++ qt control cursor position in console 2011-05-18

    I'm writing a Qt console application. I need functions to control cursor position in console(gnome-terminal)(move it back, forward, on the nex-previous line). I have tried to seek this functions in QtCore, but unsuccessful. Does Qt have at all such t

  • Windows Forms + commands from the console in C# 2010-03-06

    I've read a few topics about programs that combine Windows Forms and console applications, but it seems my question hasn't been solved yet. Is it possible to run a program from cmd-line and to be able to control the application via forms and via cmd-

  • How to record window position in WinForms application settings 2008-09-19

    It seems like a standard requirement: next time the user launches the app, open the window in the same position and state as it was before. Here's my wish list: Window position same as it was Unless the screen has resized and the old position is now

  • How to get and set window position of another application in c# 2009-09-01

    How can I get and set the position of another application using c#? For example, I would like to get the top left hand coordinates of Notepad (lets say it's floating somewhere at 100,400) and the position this window at 0,0. What's the easiest way to

  • C# Get a control's position on a form 2009-09-25

    Is there any way to retrieve a control's position in a form, when the control may be inside other controls (like Panels)? The control's Left and Top properties gives me only it's position within it's parent control, but what if my control is inside f

  • Setting the Cursor Position in a Win32 Console Application 2010-04-28

    How can I set the cursor position in a Win32 Console application? Preferably, I would like to avoid making a handle and using the Windows Console Functions. (I spent all morning running down that dark alley; it creates more problems than it solves.)

  • Get close window message in Hidden C# Console Application 2010-04-29

    I have a Windows Form that starts some console application in background(CreateNoWindow = rue,WindowStyle = ProcessWindowStyle.Hidden). Windows form gives me opportunity to stop the console application at any time. But I'd like to handle somehow the

  • Is controlling windows not owned by your process considered a malware activity? 2011-03-26

    I am planning to follow one of the suggestions made here to control window dimensions, hide/show and bring to front of a window owned by a different process from my process. Window manipulation using window-handle from different process on MS Windows

  • Multimonitor setup - window position problem when theme changed 2011-05-17

    Consider following scenario : 1.Multiple monitors are connection to one computer and they are extended. 2.My window spans to two monitors (Any window like notepad or settings wizard). 3.We change Visual Style From ON to OFF ( i.e. Changed theme from

  • Window positioning with Aero Themes (shadows) on - Window at 0,0 has some of the border hidden 2011-08-09

    I am opening a window at 0,0. When Aero and window shadow are disabled, this works just fine. If window shadow is enabled, part of the window's border (and title) are hidden above the upper / left of left edge of the desktop. Is there a way to detect

  • Stamp pdf file with control for position stamp file 2011-12-12

    Does anyone know about stamping pdf file to pdf file and also controls for positioning pdf file stamp? I have a file orginal.pdf and logo.pdf. I want to stamp logo.pdf file to file orginal.pdf at the top left of file original.pdf. How can it be done

  • Powershell script working with xml produces diferent output in PowerGUI and Powershell console 2012-01-20

    I have a following script in PS: [System.Xml.XmlDocument] $Config; function Get-ScriptDirectory { Split-Path $script:MyInvocation.MyCommand.Path } function LoadConfig { $configPath = Join-Path (Get-ScriptDirectory) Config.xml $Config = [xml](gc $conf

  • Will Windows RT ever have PowerShell ISE? 2012-03-22

    PowerShell command line is a decent app but PowerShell ISE is far more productive and allows us to manage numerous scripts easily. Will Windows RT ever get PowerShell ISE? It would make RT, which is already a very good tablet OS, even better! Thank y

  • Word and calculator do not remember last window position when opened 2013-04-24

    I have a problem with window position for Word and calculator. They don't remember the last position when open. I have tried numerous online strategies such a ctr + close, etc. What happens is that they will remember the position for the next 2 times

  • Controlling Windows in VBA 2014-06-26

    I am familiar with the process that allows you to control the size and positioning of code windows, form windows, etc. in VBA with code such as: CodeModule.CodePane.Window.Top = nn Is there any in VBA to control the size and positioning of applicatio

  • Send administrative commands to my C# Windows Service using own PowerShell CmdLets 2008-10-25

    I have a C# Windows application which runs a service. I would like to leverage PowerShell in order to offer a command line management interface for administering my running service. From my point of view, I am trying to offer the same administrative

  • Preserving window position in Interface Builder 2009-01-30

    Is there a way to preserve window position in Interface Builder? Every time I reopen a nib file, the MainWindow.xib window finds its way back to the top left of the screen, behind the window containing the interface I'm laying out. Moving it back to

  • Can you disable the VS feature that keeps separate window positions for Debugging and Editing? 2009-03-02

    I don't have the need to have my Visual Studio windows in different locations when editing versus debugging. In fact, I'd prefer my windows to stay where I put them, and not jump around as I switch between editing and debugging. Is there a way to tel

Copyright (C), All Rights Reserved.

processed in 0.218 (s). 11 q(s)