Upgrade to PowerShell 4.0 Because It Is Easier to Use

Doctor Scripto

Summary: Microsoft PowerShell MVP, Teresa Wilson (aka Scripting Wife), talks about upgrading to Windows PowerShell 4.0 because it is easier to use.

Microsoft Scripting Guy, Ed Wilson, is here. Today I continue my series of posts about upgrading to Windows PowerShell 4.0 by turning over the keyboard to Windows PowerShell MVP, Teresa Wilson. Teresa is also known as the Scripting Wife, and she is active in the Windows PowerShell community with events such as PowerShell Saturday, PowerShell User Groups, and PowerShell.org. Take it away Teresa…

Hi everyone. Teresa, aka Scripting Wife, is here. I know that everyone talks about Desired State Configuration (DSC) as the big exciting feature in Windows PowerShell 4.0. Perhaps if I worked on servers, I would agree. I have heard Ed come home many times complaining about how someone messed up a server by changing stuff that was not supposed to be changed. He also gripes about people ignoring change management procedures (whatever that is). So yeah, I guess it is a big deal.

But the reason I like Windows PowerShell 4.0 is simple—it is easier to use. Here are some of my favorite features in Windows PowerShell 4.0.

#requires

On my laptop, I run as a normal user. This is fine for a lot of things. I can even open the Windows PowerShell ISE and write a quick script—mostly this works. But there are issues. It seems that a lot of things in Windows PowerShell require Admin rights. So I have to start the Windows PowerShell ISE again with Admin rights. The problem with this is that lots of things do not really say, “Permission denied.” Instead they say something along the line of, “Resource failed to work” or simply “Get lost, Script Monkey.” I mean, really—how rude!

So when I figure out what happened (usually by asking the Scripting Guy), I like to make a note of it. With the new #requires feature, it is easy.

Image of command

Ignoring blank lines

One of the things that used to bug me (sort of) was that when I used Import-CSV, I had to make sure that my comma-separated value (CSV) file did not have any blank lines. If it did, things would simply blow up. I even had to ask Ed to write a post about cleaning out blank lines from text files (see Deleting Extra Returns and Line Feeds from a Text File Using Windows PowerShell).

Things for me got a lot easier for me when the Windows PowerShell team fixed the Import-CSV cmdlet so that it ignores blank lines when it imports stuff. This means that now when I import a .csv file, if it has blank lines, I do not get empty records, errors, and false things in the results. Sweet!

Image of file

Here is the import. Notice that the blank line is ignored.

Image of command output

A couple of other things

There are a couple of other things in Windows PowerShell 4.0, which for me personally, add up to a big deal. One thing is that when I use Get-Module, it now shows me the version. This is really cool for when I download modules from the Script Center Repository or some other place. It is not a big deal for things that come with Windows PowerShell—only for the modules I get from friends. Here is an example:

PS C:\> Get-Module PowerShellISEModule

 

ModuleType Version    Name                 ExportedCommands

———-          ——-        —-                           —————-

Script     4.0        PowerShellISEModule     {Add-HeaderToScript, Add-Hel…

Another thing that I like is that when I use Remove-Item with the –Recurse switch, it now deletes things from subfolders. I think this was probably a bug fix because previously, it wouldn’t work, and I would think I was doing something wrong. It was pretty annoying. But now it works like I expect, and that is sweet.

For me, Windows PowerShell 4.0 is all about making things easier. But to be honest, it was not a big decision. I was already running Windows 8 on my new laptop, so when Windows 8.1 came out, of course I upgraded. And all of a sudden, now I am using Windows PowerShell 4.0. It was that easy. The fact that Windows 8.1 came with Windows PowerShell 4.0 was an unexpected bonus. I hope this helps when you are making your decision about upgrading.

~Teresa

Thank you, Teresa, for an interesting post. Upgrade to Windows PowerShell 4.0 Week will continue tomorrow when I will introduce another guest blogger.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

0 comments

Discussion is closed.

Feedback usabilla icon