Learn about Windows PowerShell
Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to change the Internet Start page on his Microsoft Surface .
Microsoft Scripting Guy, Ed Wilson, is here. It is no secret that I love my Microsoft Surface. Just before our trip to Europe, I bought a nice Microsoft Surface Pro 2 with extra memory and disk space. The thing is fast and light. With my real-touch keyboard (left over from my Surface RT), it is a great laptop replacement. I love the fact that it has Windows PowerShell 4.0, and even the Windows PowerShell 4.0 ISE.
To me it is great. I stuff it in my camera backpack, and am ready for a day of exploration and discovery. We stop for a cup of coffee, and I whip out my Surface. With its nearly instant On feature, and I can check email, write a blog post, take pictures and share them on Twitter and Facebook. And with Office Live, I can work on my novel, update our Excel spreadsheet itinerary, and even work on my PowerPoint slides for the Windows PowerShell Summit. In short, the device is nearly perfect.
FCC disclaimer: Whereas I work for the Microsoft Corporation, they did not buy my Microsoft Surface Pro 2. I paid full price for it at the Microsoft Store in Charlotte. Microsoft did not buy the Surface Pro that the Scripting Wife uses either. We bought the devices simply because we think they are useful and extremely cool.
Here is the Scripting Wife reading on her Surface:
Where do I change the Start page? I looked and looked, and I was unable to find a Tools type of menu. Nothing appearing in the image here seemed to help:
I was finally able to find out how to use the graphical user interface to change the Start page on my Surface RT (and also on my Surface Pro 2). I am not sure if this was added with Windows 8.1, or if it was always available in Windows 8 (on the Surface), and it took me a year to find it. Anyway, one day it dawned on me, “I can use Windows PowerShell to do this!”
And because there are literally five Surface-types of devices in our Scripting Household (not to mention three non-domain joined laptops also running Windows 8.1), it seemed to me that using Windows PowerShell to set a useful Start page was much easier than trying to type complex URLs by using a virtual keyboard.
Don’t get me wrong. I like touch screens as much as the next person. But to me, a virtual keyboard is just that—virtual and not real. Call me old fashioned, but I like a real keyboard that has give and tactile feedback. There is a very short cross-over period for me where the annoyance of dragging out a Bluetooth keyboard or finding my touch keyboard and attaching it is worth the effort of not having to spend five minutes playing hunt-and-peck on a virtual keyboard.
This is super simple. It is a one-liner. But because I am going to use it at least eight times, it is worth the effort to write a script. I can put this in a function, a module, or a whatever. Right now, I broke the lines out a bit to make it easier to read, but it is one logical line of script.
The first thing I like to do is to see if I can read the registry value that contains the start page for Internet Explorer. I found the value stored in the hive here:
To read the value, I use the Windows PowerShell Registry provider. The command is shown here:
$path = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'
$name = 'start page'
(Get-Itemproperty -Path $path -Name $name).$name
Does the script work? Sure it does! Here are the results:
So, I know that I can get to the Start page in Internet Explorer. How about also setting it? All I need to do is change Get-ItemProperty to Set-ItemProperty and pass a new value. Here are the changes:
$value = 'http://blogs.technet.com/b/heyscriptingguy/'
Set-Itemproperty -Path $path -Name $name -Value $value
When I run the script this time, there is no output, which is fine. I can use the Get-IEStartPage script to verify if I want to, but the best way to check is to simply open Internet Explorer. Here is the output—as you can see, there is nothing returned:
When I open Internet Explorer, I see that it worked as intended.
Join me tomorrow when I have guest blogger who will talk about working with streams. It is a cool topic, and you do not want to miss out.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy