2

I am trying to migrate some code to Windows 10/PS 5 and having issues. It started with MS killing the ability to Pin to Taskbar, and now I am having issues with the assignment lines flagged in the code below. I am wondering if there is some sort of a resource document for all the changes/bugs in PowerShell 5, or am I going to just be waiting for things to break and then Googling to find solutions/bugs?

$psHost = Get-Host
$psWindow = $psHost.ui.rawui  

$newSize = $psWindow.buffersize
$newSize.width = 90
$newSize.height = 1000
$psWindow.buffersize = $newSize ###
$newSize = $psWindow.windowsize
$newSize.width = 90
$newSize.height = 50
$psWindow.windowsize = $newSize ###
Gordon
  • 6,257
  • 6
  • 36
  • 89
  • What is `$pswindow` - can you show that assignment? Also, what "issues" are you having – Mathias R. Jessen Dec 12 '15 at 13:18
  • OP revised. It's failing in a try/catch, and I am now revising it to show me the actual error, but what is perhaps more odd is that I am now finding it to be intermittent. I am testing now on a VM, and when I took the VM full screen it started to work, and when I brought it back to Windowed it continued to work. Checking now to see if the VM may be doing something with scaling automatically that affects this. I have a customer who is seeing the same behavior on a real machine as well. – Gordon Dec 12 '15 at 13:36
  • Looking deeper, it's the buffer size. It seems that buffer size can't be 90 in Windows 10. Works fine in Windows 7. I may try to standardize on 120 or something if that works. But man would I like some real doco from Microsoft. – Gordon Dec 12 '15 at 13:45
  • They've change the console in Windows 10, so that the buffer automatically resizes with the Window – Mathias R. Jessen Dec 12 '15 at 14:07
  • Only problem I have with your code is that buffer can not be less than window size. So, I just reverse you assignments order and it work well: `$psWindow.windowsize = @{Width=90; Height=50}; $psWindow.buffersize = @{Width=90; Height=1000}` – user4003407 Dec 12 '15 at 14:12
  • 3
    Or more robust approach (since window size can not be greater than buffer size): `$psWindow.WindowSize = @{Width=1; Height=1}; $psWindow.BufferSize = @{Width=90; Height=1000}; $psWindow.WindowSize = @{Width=90; Height=50}`. – user4003407 Dec 12 '15 at 14:40
  • PetSerAl, thanks for that much cleaner syntax! – Gordon Dec 13 '15 at 14:07

1 Answers1

1

There is no solidified resource that can tell us what's usable in a given version since you can mix and match PowerShell version 2.0 and 5.0 with (currently supported)Windows 7 and up.

PowerShell v5 can be installed on Windows 7 and later. This means there's a lot of things that can be different between which version of Windows you're running and which version of .Net you're running.

For a quick read of what's different in PowerShell 5.0, I'd suggest this article: https://technet.microsoft.com/en-us/library/hh857339.aspx

One of the more notable improvements I've come across so far is that PowerShell 5 finally enabled transcripts to be used in the PS ISE(integrated scripting environment).

If your workplace has modern machines with Windows 10, it is easy to write scripts with that in mind. Otherwise, it's best to write scripts for the lowest common denominator in use. I often find clients that still have Windows XP and Windows Server 2003, so I try to write scripts with PowerShell 2.0 in mind.

==

As for the window size, the comment from PetSerAl is quite usable(adopting in answer since comments are sometimes subject to deletion):

Since window size can not be greater than buffer size:

$psHost = Get-Host
$psWindow = $psHost.ui.rawui
$psWindow.WindowSize = @{Width=1; Height=1}
$psWindow.BufferSize = @{Width=90; Height=1000}
$psWindow.WindowSize = @{Width=90; Height=50}
Booga Roo
  • 1,665
  • 1
  • 21
  • 30