Ari Roth
Ari Roth

Reputation: 5534

Powershell: Setting the screen resolution in a Windows 8 VM

I am running a series of Coded UI tests on a VM through Visual Studio Team Services. The problem is, a lot of the tests are failing because the screen resolution is too low when someone isn't actively remoted in (which is always, while the tests are running). With the resolution as low as it is (I'm pretty sure it's 800x600), some items are getting cut off by other items, and controls that Coded UI needs to find and click can't be clicked because they're suddenly behind other controls.

So I'm looking for a way to set the default screen resolution of the VM to something larger, like 1280x1024.

So far I've come across two techniques. One is a rather large script that involves intermingling C# and Powershell syntax. That could work, but the other way seems simpler: edit the registry to set the default screen resolution. This approach works slightly better for me, because I don't have to add an entirely new Powershell file to the release definition (which I would do for the large script); instead I could just add two lines to the existing script that's already running.

Per this article, there are two registry settings I need to edit, which I can do via a simple call to the Remove-ItemProperty/New-ItemProperty pair of functions. They are:

The problem is this line from the article:

Where GUID is a randomly generated GUID.

So the question is, is there any way to know the GUID being used in these keys? Or is there any way in Powershell to either get them or get the entire key and parse out the GUID?

Upvotes: 0

Views: 1735

Answers (1)

Matt Szadziul
Matt Szadziul

Reputation: 164

If you just need to extract the GUID string, you can run this:

Get-ChildItem -Path "HKLM:\System\CurrentControlSet\Control\Video" | % Name | ForEach-Object {$_.split("\")[5]}

If you need to get the GUID from VMs remotely, you will probably need to look into the usage of .NET Microsoft.Win32.RegistryKey or WMI StdRegprov classes.

Alternatively, if PowerShell Remoting is enabled:

Invoke-Command -ComputerName $Computer -ScriptBlock {Get-ChildItem -Path "HKLM:\System\CurrentControlSet\Control\Video" | % Name | ForEach-Object {$_.split("\")[5]} }

Upvotes: 1

Related Questions