PowerShell Not Your Father’s Command Line Part 29 of 31: Demystifying MSDN and PowerShell static syntax

Originally, this post was going to be about GUIs, but after waking up this morning and seeing a comment on Part 28, I figured that I’d address that comment in this post.

Paul Bendall writes:

But how does an ITPro without a developer background start to use MSDN and understand terminology such as static, override, []::Something?

Let’s demystify some of the things at MSDN so that maybe you guys without a developer background can make sense of it.

Terminology Elevator – Ground Floor – Objects

Objects are… um… objects in programming terminology. An object could be words, numbers, a computer, anything really. In Appendix B in our book, I talk about objects at a really high level. Let’s take a similar approach here. Let’s talk about a keyboard.
Rapoo Keyboard from Hong Kong
A keyboard is an object. It has keys – which means that a keyboard could have a collection of objects. Yes, collection can be a technical term referring to a grouping of like or related objects. Now let’s look at a keyboard key… what can you tell me about it?

  • What color is the key?
  • What character or characters are on the keys?
  • How big or small is the key?
  • Is the key enabled?

The answer to these questions would be called properties of the keyboard key. They describe the object in terms of adjectives and capabilities.

  • Press the key.
  • Release the key.

These actions show that the key can respond to events. When an event happens, you can trigger a piece of code to run. In some cases, you may be able to have code run before or after an event happens, depending on the object and event.

Now let’s look at the Caps Lock key. When you press it, the alphabetical keys TYPE CAPITAL LETTERS. This means that not only can this key respond to being pressed, but it also can perform an action called a method. Yes, this also means that the object may call a method while responding to an event.

So an object can have properties, methods, and events.

Terminology Elevator – Level 1 – Class, Static, and Constructor

A class is a container that holds the methods, events, and properties of an object. Using our keyboard key example, a class would be the collection of all of the properties, methods, and events that belong to a keyboard key.

If you find yourself using the New-Object cmdlet and getting the “Constructor not found.” error, that basically is telling you that you are working with a static class.

A constructor is a piece of code that states how to create a new object. This is the piece of code that gets run when an object is created with the New-Object cmdlet.

If the constructor isn’t in the class, then the class is considered static. If something is called static, this means that they are not created, destroyed, or changed – they are simply used.

In PowerShell, the :: operator is used to call out to static methods and properties. The syntax is as follows:

[Namespace.Namespace.ClassName]::Method()

or

[Namespace.Namespace.ClassName]::Property

Yesterday, we looked at the System.Windows.Forms.SystemInformation class and some of its properties. There is also a TechNet article on using static classes and methods in PowerShell.

Terminology Elevator – Level 2 – Assemblies and Namespaces

Assemblies and namespaces are ways to organize code. An assembly is a physical way of organizing code – commonly in a DLL file. A namespace is a logical way of organizing code – grouping code for the same object or collection of objects together.

Looking at the top of the SystemInformation class page on MSDN, you can see that this particular class lives in the System.Windows.Forms.dll assembly. It also belongs to many namespaces – collectively, it belongs to System.Windows.Forms. However, Forms is a namespace that belongs to Windows, which is a namespace that belongs to the System namespace.

Russian Matryoshka dolls - pic taken from http://nelietatravellingadventures.blogspot.com/2010/11/matryoshka-or-nesting-dolls-from-russia.html
One thing you’ll notice with the naming scheme is that the namespaces are stacked like Russian matryoshka dolls – the largest namespace is on the outside, and the smaller namespaces are nested inside, all the way down to the class – which is like that tiny doll at the end.

Terminology Elevator – Observation Deck – Overrides

By default, there are actions that a command can do automatically. However, you may want to customize those actions, which can be done by overriding the action. Basically, if you write code that overrides the default behavior, your code supersedes the default code.

Conclusion

A lot of what you’ll see on MSDN is based on object-oriented programming concepts. Hopefully this post gives you a little idea as to what those terms mean and can help you on your way in using static classes and methods in PowerShell.

PowerShell Not Your Father’s Command Line Part 28 of 31: What is the .NET Framework?

While talking with Hal and Jonathan on the PowerScripting podcast, I was asked the question “What is .NET?” Of course, I mentioned that it’s a framework, but then I choked… the .NET Framework is a huge thing to try to tackle like that, especially when talking with IT pros. Being a developer and working with the .NET framework, I can tell you it’s a collection of libraries that have a whole lot of code that we don’t have to write and can use to make our developing a lot easier. However, I didn’t need to get into it as a developer and needed to suppress the developer speak.

What is the .NET Framework?

When I say that the .NET framework is huge, I’m referring to how much it covers – be it web services, web applications and websites, desktop applications, or yes, even shell scripts. There are libraries – collection of objects and commands – to make it easy to access data, manage configurations, work with accessibility and assistive technologies, address security concerns… just to name a few things that you can do.

What is .NET Framework in terms of PowerShell?

Sean Kearney, a.k.a. The Energized Tech, recently wrote a post titled Understanding .NET from the perspective of an IT Professional. In that post, he talks of assemblies, which developers are quite familiar with. If you have to support developers and they happen to ask you which assemblies are installed on your machine, you could use this:

[appdomain]::CurrentDomain.GetAssemblies() | Select FullName

This command will list all of the assemblies in the current domain. Each assembly listing includes the name, version, culture, and public key token; these fields are key to developers as they need to use those lines when configuring their .NET projects that may live on your server.

The output may look something like this:

PresentationFramework, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

If you want to work with an assembly that isn’t loaded by default, you could use the Add-Type cmdlet in PowerShell 2.0. For example, let’s say we’re writing a script that gets a computer’s NetBIOS name, the logged-in user’s user name, and the domain. These can easily be accessed by System.Windows.Forms.SystemInformation. To see these details, run the following commands:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SystemInformation]::ComputerName
[System.Windows.Forms.SystemInformation]::UserName
[System.Windows.Forms.SystemInformation]::UserDomainName

And as suggested by Aleksandar Nikolic, here’s a good way to see what static properties and methods belong to the SystemInformation class:

[System.Windows.Forms.SystemInformation] | Get-Member - Static

As you can see, you can use these .NET assemblies from within PowerShell, as PowerShell is built on top of the .NET Framework.

If you have questions about Add-Type, I’d first recommend checking out:

Get-Help Add-Type -examples

Learning More

As I mentioned, the .NET Framework is huge enough to have its own podcast. You can find out more about .NET in the community through the .NET Rocks! podcast, hosted by Carl Franklin and Richard Campbell (one of the co-hosts of the IT pro sister show called RunAs Radio).

Someone else listening to the podcast suggested reading MSDN. My advice – just be familiar with the MSDN Library and how to search it as needed. You’ll find this to be a great resource, especially if you’re going to write your own custom compiled cmdlets, providers, and binary modules.

This was just a high level overview of what the .NET Framework can do. If you want to see more things you can do with the .NET Framework, check out some of the fun projects over at Coding4Fun!

Matt and I want to hear what you’ve thought about the series so far. Leave us comments on our posts or get in touch with us. I can be emailed at sarah at codinggeekette dot com.

Special thanks to Aleksandar Nikolic for catching the typo in this entry. The Add-Type command has been updated.

PowerShell The Community’s Command Line Part 27 of 31: It Takes a Community to Raise a Language

Much like the saying It takes a village to raise a child, it takes a community to raise a programming language. Without passionate people in that community, the word won’t spread and a language can die. Yesterday, I talked about some of the cool community resources and sites. Today, I want to salute those who are working on community projects with PowerShell. These are just a few of the many out there.

StudioShell, by Jim Christopher (@beefarino)

http://studioshell.codeplex.com/
StudioShell is an integrated PowerShell host available inside Visual Studio 2010 and 2008. This tool exposes Visual Studio’s extensibility points and makes it easier to extend your Visual Studio from the command line rather than from compiled binaries. Jim will be giving a presentation on his StudioShell project and using it to extend Visual Studio at CodeStock 2011 down in Knoxville, TN this June.

MongoDB PowerShell Provider, by Jim Christopher

http://mosh.codeplex.com/
If you’re in an environment where you need to manage a Mongo database, then the MongoDB PowerShell Provider may make your life a little easier in managing the database from within PowerShell. This project is nicely documented both on the CodePlex site and from within PowerShell.

PowerShell Script Provider, by Oisin Grehan (@oising)

http://psprovider.codeplex.com/
While developers who can think out a provider’s logic may be more comfortable with writing the provider in C#, this provider allows IT Pros and those comfortable with PowerShell to write their providers in the PowerShell scripting language. Oisin Grehan, PowerShell MVP and PowerShell provider guru, is the guy behind this project. It’s great to see the option of writing providers in PowerShell, as working with the scripting technology directly in its own language makes more sense to many scripters.

Show-UI: The PowerShell WPF Toolkit

Show-UI
For those who have our book, disregard the recommendations on page 397 on the two things to help with WPF apps in PowerShell, as WPK and PowerBoots are merging. Show-UI is the project that they are merging into. Yes, you can use PowerShell to create GUIs. Show-UI is a project that can help make that process even easier in PowerShell. Shoutouts to the coordinators and developers – Jaykul, Doug Finke, and James Brundage.

Others?

Got any other PowerShell projects that you want to share? Leave me a comment!

Why Microsoft? Innovation! – The #WhyMsft RT Contest

On Monday, Why Microsoft ran a retweet contest on Twitter:

Tell us in one word #WhyMsft for your business & win! Find out how here: http://bit.ly/WhyMsftless than a minute ago via HootSuite Favorite Retweet Reply

I wasn’t sure what word to use. I’ve always been a fan of Microsoft’s products, and even my Linux and Mac fanboy friends have accepted me although I prefer a different operating system and set of tools. Whether it’s writing an app in Visual Studio, communicating across the house with my husband via Lync, using my Natural Ergonomic Keyboard 4000, playing a Microsoft Game Studios game like Age of Empires III on my PC, playing games on Xbox LIVE via my Samsung Focus Windows Phone, being a button masher while playing Castle Crashers on my XBoxMicrosoft is everywhere in my life.

I hadn’t gotten a Kinect yet, but I’ve had a chance to play it over my friend Jeff‘s place with his family. Watching the kids play Kinectimals or other Kinect games, it made me realize how much gaming at home has changed over the years. Nintendo Power Pad, Nintendo Zapper, Nintendo Power Glove… those were the cool pieces of hardware back in the day when I was a kid. Over the years, we got into controllers with rumble packs… and then more advanced controllers like the guitar controllers for Guitar Hero or Rock Band and WiiMotes. Kids in arcades are familiar with games using cameras to pick up body movements – like the boxing game. Now, we can finally get something like that at home thanks to the Kinect.

Innovation RT @whymicrosoft In one word, #whymsft for your business? for a chance to win! Rules: http://bit.ly/WhyMsftless than a minute ago via web Favorite Retweet Reply

I had a conversation with a friend, and she played devil’s advocate, suggesting that Microsoft wasn’t innovative. Where was the Sony Playstation’s equivalent of the Kinect? What about the Nintendo equivalent of the Kinect? Where were those when Microsoft brought out the Kinect? The Kinect is just one piece of technology that shows Microsoft’s innovation.

With the upcoming release of the Kinect SDK, imagine what the community can come up with! They have a Microsoft Innovation Center site that shows many other ways that they are innovative. In addition to being a company of innovation, they encourage the community to become innovators. Dare I say that they spark innovation? After all, take a look at the BizSpark, WebsiteSpark, and DreamSpark programs! Not only through DreamSpark, Microsoft can stir students’ imaginations and encourage innovation through the Imagine Cup. These are only a few of their projects that encourage innovation.

Sure, I could’ve said “Awesomeness”, as “awesome” is a word I overuse. Or I could’ve said PowerShell or any one word name of a Microsoft tool that I use. But innovation truly fits.

Check out their #WhyMsft Retweet Contest results post to see what others had to say!

PowerShell My Father’s Command Line Part 26 of 31: Start Spreading the News…

I’m watching this week’s episode of Glee again while writing this post, and the “I Love New York/New York, New York” mashup really inspired this title. I have to give a shoutout to my dad in the title, as while he isn’t technologically inclined, he taught me the value of networking and establishing relationships. He was a union leader for the city’s emergency response service for many years, and in those years, I watched as he networked with people in his line of work and those who impacted his line of work – councilpeople, mayors, senators, and the like. Watching him, I learned how to network and how to participate in communities.

Up until this point, Matt and I have been talking about scripts and code in PowerShell, but there’s more than just that. If the language didn’t have a community behind it, it would fall flat and not continue on like it has been. So let’s do a shoutout to some of those in the PowerShell community!

2011 Scripting Games

Hey, Scripting Guy!, the Scripting Games, and the Scripting Wife!

Ed Wilson is also known as the Scripting Guy over at Microsoft. He answers languages on various scripting technologies, with PowerShell being the focus nowadays. Whether he’s answering questions in the Hey, Scripting Guy! blog, posting on Twitter as @scriptingguys, speaking at various events throughout the world, or writing books, Ed is a great community resource when it comes to PowerShell! One of the events that he promotes on his blog are the Scripting Games, and the 2011 Scripting Games were no exception! This is a great contest for testing your scripting chops against other PowerShell scripters, competing in either a beginner or advanced level. What made it even neater to follow this year was that Scripting Wife joined the games. While I didn’t have time to participate this year due to other timing conflicts, I did enjoy reading the journeys of Scripting Wife as she learned working with PowerShell. Check out the Hey, Scripting Guy blog, as Ed covers some of the topics that you’ve probably wondered about.

PowerScripting Podcast

PowerScripting Podcast

Hosted by Hal Rottenberg and Jonathan Walz, the PowerScripting podcast is recorded live on UStream every Thursday night at 9:30pm Eastern Daylight Time (GMT -4). They feature various people in the PowerShell community – including talking with Jeffrey Snover (father of PowerShell), the directors of PowerShellCommunity.org, PowerShell MVPs, people on the PowerShell team, vendors of PowerShell products, and even those on product group teams whose products can benefit from PowerShell. While recording, they’ll take questions from the audience via the chat channel. I was able to catch the show on PowerShellCommunity.org, and it was neat to see how they record the podcast. After recording the show, the hosts play music while wrapping up the show – always great to rock out with these guys! Matt and I will be on PowerScripting tonight talking about our book and our love of PowerShell!
PowerShellCommunity.org

PowerShellCommunity.org

Run by the community for the community, PowerShellCommunity.org features news, forums, learning resources, steps for forming a PowerShell user group, and a poshcode.org-powered script repository. Special thanks to the sponsors of the site who provide financial support to enable the online community presence and support local PowerShell user groups – including Microsoft Windows Server 2008 R2, Quest Software, SAPIEN Technologies, Inc., Compellent, Idera, and Pragma Systems.

PowerShell.com

PowerShell.com is another community for PowerShell scripts, tips & tricks, webcasts, blogs, and other resources. Once again, Idera and Compellent are sponsoring another community resource (in addition to PowerShellCommunity.org). Concentrated Technology and nSoftware also sponsor PowerShell.com. This site also features the Master-PowerShell eBook written by Dr. Tobias Weltner. Yet another great resource for PowerShell scripters!


Get-ToThePrompt -at PowerGUI.org

PowerGUI.org

Quest Software, Inc. runs PowerGUI.org, a free community for PowerGUI users. PowerGUI is a script editor and administrative console based on PowerShell. Their community site includes tutorials, PowerPacks, forums, wikis, demos, and other goodies related to PowerGUI. If you’re using PowerGUI, then this site is a must-have resource!

#powershell on irc.freenode.net

If you’re an IRC user, definitely check out the #powershell channel on irc.freenode.net. Don’t have an IRC client? mIRC, xChat, and others are out there. Of course, freenode is awesome and has a webchat available!

Others?

These are just a few of the PowerShell resources and communities out there. Got any you want to recommend that I haven’t mentioned here? Leave me a comment!

Scripting – It’s Not Just for Developers!

Recently, Matt sent me this article on IT Pros are not feeling the love from Microsoft and asked for my feedback. Now I need to qualify this for those who don’t know me that (1) I used to work in IT doing system and database administration and desktop support and (2) I’m married to an awesome IT guy who helps keep me up on IT technology that I don’t necessarily pay close attention to.

Fears of the Cloud

In the clouds...

While there’s the cloud fear, IT pros need to understand that while we developers can write for the cloud, we don’t always necessarily understand the support and setup issues from an infrastructure point of view. So you IT pros shouldn’t feel threatened by these technologies – you need to understand that IT isn’t getting eliminated by these. But you also need to understand the cloud so that you can support your developers who are writing for it. And if the recent BPOS outages and the Amazon cloud outage are signs of anything, clouds can be unstable and you IT pros need to be able to help support your companies when their clouds fail and need to recover to something else. (And of course, there are private clouds… so don’t think you’ll get pushed out with cloud computing.)

Ch-ch-ch-changes

Ms. Shinder mentions that most people are resistant change, which is true. However, if you’re working in technology and resistant to change, then you’re in the wrong industry. Technology is constantly changing, and if you want to go forward in your career, you need to keep up with it. Falling behind leaves you to being that legacy support person. While you hang on to old technologies, they inevitably will be phased out and then you’ll be out of a job and find it hard to get into something new because you resisted change in an ever-changing field.

Code Monkey Like You?

Then there’s the case of IT pros evolving into developers. How many people really enjoy having to visit each machine in their care for updates? Wouldn’t it be easier if you could push out machine image updates automatically? Sure, you could setup a Ghost session and update a lab in downtime via multicast (ah the memories), but you could also probably script the process and not have to be there to click the “Yes” / “No” prompts that may come up. Silent installers don’t typically just work automatically – you have to run an executable at a command line with typically a /s or some other switch. If you’re familiar with working at a command prompt for tasks like that, then PowerShell isn’t as complicated or as scary as you think.

IT pros who are smart about staying ahead of the curve understand the importance of automating processes and making management easier. Be it with shell scripts in a Unix shell, VBScripts, WScripts, JScripts, batch scripts… it’s not as if scripting is new to IT work. I know some IT pros of yore who used Perl scripts to help with server management. If you were an IT pro then, I could understand complaining about scripting – while the logic (thinking about it in English) to solving a problem was simple, the syntax was pretty screwy. At least PowerShell comes a bit closer to being easier to understand – Start-Service does just what it says it does. There may be other parameters after a command, but you know what… the PowerShell help system is awesome enough to help you figure this out. You don’t have to dig through man pages or try to find online documentation. You have Get-Help Command –examples, and there are useful examples with descriptions to help you on your way.

Demystifying PowerShell

PowerShell is easy to navigate and easy to learn. It doesn’t take a lot of effort if you already have a scripting background. And if you don’t have a scripting background… as long as you can think the problem out in English, there’re guides out there who can help you through this. Matt and I have written a book that is good for just that – guiding the average IT pro with minimal to no scripting background through the craziness known as PowerShell. Give our book a chance to change that ‘PowerHell’ experience to ‘PowerFull’.

PowerShell Not Your Father’s Command Line Part 22 of 31: Good PowerShell Things Come in Nifty Packages

Have you found yourself writing PowerShell objects that you’d love to share with others? What’s the best way to get these things distributable? Well… with PowerShell 2.0, you have two different types of packaging – snap-ins and modules.

Snap-ins

Snap-ins were available in PowerShell 1.0 and are still supported in PowerShell 2.0. In order for these to be used on a machine, they typically need to be installed first. Once the snap-in is installed on the machine, then it should be in a spot where PowerShell can see it. The best way to tell if it’s there is using the following command:

      Get-PSSnapIn -Registered

This will show all snap-ins that PowerShell can see, with the exception of those snap-ins that came with PowerShell. If the snap-in that you’ve installed doesn’t appear, then you may need to use the Installer Tool that comes with the .NET Framework to register the DLL.

Once the snap-in appears in the list, then you can bring it into the PowerShell session with the Add-PSSnapIn cmdlet. So let’s say you were installing the IIS 7.0 PowerShell snap-in,downloadable from IIS.net. Once the MSI file was run, the IIS snap-in should be installed on the computer. At this point, you should be able to run the following command:

   Add-PSSnapIn WebAdministration

While good things are already packaged in snap-ins, what if you have your own things to package in a snap-in? How do you create your own snap-in? MSDN covers this in depth.

You can also use the Import-Module cmdlet to bring in a snap-in into the PowerShell session. Tome Tanasovski covered this – including why you would choose Import-Module versus Add-PSSnapIn – in a Hey, Scripting Guy! blog post.

Modules

Modules are the newer, improved way of packaging PowerShell goodies for redistribution. Some of the goodies may include are providers, cmdlets, functions, scripts, dependent assemblies, and help files.

To see what modules are available on your machine, use the following command:

    Get-Module -ListAvailable

Unlike snap-ins, modules do not necessarily need to be installed. They need to have a certain folder structure and live within one of the directories listed in the PSModulePath environment varible.
To bring a module into your PowerShell session, use the Import-Module command. For example, if you downloaded the Windows Installer PowerShell module to use PowerShell to investigate MSI files, then you would import this module with the following command:

     Import-Module MSI

If you’re writing custom cmdlets in C#, then you’ll create a binary module – this is the DLL you create when you build your class library. If you’re writing scripts, simple functions, and advanced functions in PowerShell then you’ll create a script module, in the form of a .psm1 file. See my 4/26 presentation recap for my custom script module that is bundled with a module manifest, making it a manifest module.

The custom module that I had created shows the structure of a module, especially when help files are included. If you download the custom module, you’ll notice that the help files are simply text files. If I am redistributing a module, I typically go to the module’s folder and zip it at that level, so that the module just needs to be unzipped to one of the modules folders listed in the PSModulePath environment variable.

Matt and I have mentioned a variety of snap-ins and modules in our series so far, but there are plenty of others out there that may be useful for you. If you do a search in your favorite search engine for “PowerShell snap-in” or “PowerShell module”, you’ll be able to see what else is out there.

Seeing What’s In These Packages

While I explained how to import these snap-ins and modules into your PowerShell session, I didn’t tell you how to see what you get with them. Once your snap-in or module is in your PowerShell session, then you can use the following command to learn more about that module or snap-in:

     Get-Command -Module ModuleOrSnapInName

As always, Matt and I enjoy getting feedback on the series. If there’s something you want to see us cover, please get in touch with us. You can email me at sarah at codinggeekette dot com.

Published… For Real…

For those of you wondering why I’ve been talking PowerShell so much lately, it’s because Matt Hester (IT Pro evangelist at Microsoft and all-around awesome guy) and I co-wrote a book on PowerShell. When we first started writing this book, I was just a tech editor, but he offered me a chance to write appendices. I didn’t realize how much work goes on behind the scenes, but all I can say is … wow! Our editors have editors, who also have more editors. There are a great amount of eyes on the book – special thanks to all of our editors at Wiley (the publisher of the Sybex imprint), especially to Agatha Kim, who puts up with Matt’s and my randomness! Also thanks to Dick Margulis, our developmental editor, who steered us the right direction and laughed with us along the way!

When I came home today, I found a box on my doorstep from Wiley. I knew it was either a random shipment of books for our local user groups or the real deal. As I cut through the tape on the box, I knew this was it, as Matt’s copies arrived at his house already. And sure enough… I have a book…

Sarah and her book!!!

As you can see, I’m a bit happy about this! I also received an email from Amazon this morning stating that my copy from there will be arriving on May 24, which is plenty of time for our book signing party at Buckeye Beer Engine in Lakewood, Ohio on Friday, May 27th. All are welcome to attend the book signing. We will have food and books and authors to sign the books. We will also be giving away some swag to those who RSVP online and attend the event. If you’re interested in RSVPing, see http://qtlil.me/psbookparty for your ticket. The event is FREE!

I hope you can come out and celebrate our book release, as Matt and I will be happy to sign books and greet all who attend!

Overspecialize, Generalize, or Find that Happy Middle…

I’ve been dealing with this dilemma for the past couple years. While I’ve had a Microsoft MVP award for Visual C# these past couple years, I’ve wondered if I’ve gone too generalized to have it renewed this year. We’ll find out in July if that’s actually true. Even if that’s true, I’m still going to be on that mission – to find the happy middle between overspecializing and generalizing.

Add to it that I saw this tweet, and it really has me thinking:

The key to being a programmer today and in the future. Don’t over specialize, don’t stop learning, stay close to your customer.less than a minute ago via TweetDeck Favorite Retweet Reply

For me, I don’t want to go down the road of overspecializing. I’d feel like that guy who painted himself into the corner of the room, trapped. However, I don’t want to be too general, because while it’s helpful being a jack of all trades, it’s also hard to see where it’s best to place me, which projects are best to utilize my skillset. I’d like to be the master of some, not the master of none. In a way, I want to be kinda like my Microsoft MVP expertise of Visual C# – I want to be useful on many types of projects.

Visual C# is my current expertise area, but I also am dabbling with PowerShell. The beauty of it all, though, is that I am using Visual C# while playing with PowerShell – how do you think my custom cmdlets are written? If you’re in the Cleveland area on April 26th, I can show you some custom cmdlets at the Cleveland C#/VB.NET SIG. You can also see some of my custom cmdlets in appendix D in Automating Microsoft® Windows Server 2008 R2 Administration with Windows® PowerShell 2.0.

That’s not the only time I use Visual C# though. In my day job, I work on ASP.NET websites, web applications, out-of-browser Silverlight apps – all with Visual C# as their base. I’m working with ASP.NET MVC and ASP.NET WebForms, which I use with Visual C#. Here at home, I play with Windows Phone development, and that too… written in Visual C#. I also write web services – be it ASP.NET Web Services or WCF – in Visual C#. Writing Windows Forms and WPF applications… those are also done in Visual C#. It’s such a handy language, with a variety of applications.

Now granted there’s a lot of theory behind Visual C# and how it’s built. There are people who specialize in that, in how the compiler works, in how the language works under the covers. And then there are people like me – on the quest of finding the happy middle. While I would love to understand how its work under the covers, I really like seeing how it is applied in the field as well. Understanding how it works under the covers can give me a better background of why its strengths and weaknesses are the way they are, and it would help me play off of the strengths and weaknesses better in code. However, understanding how it is applied helps me to put Visual C# to work in my everyday business world and in my side projects.

I like tinkering with the many uses of the language to see how it can be used, and the same can be said with any other language I’ve worked with – the various VB derivatives (VB, VBA, VB.NET), python, and JavaScript being the more recent languages. I like the continuous exploration to see what I can find. I don’t want to stop learning, and I definitely don’t want to overspecialize. I hope I’ve found a happy middle, as it feels like I’m finally there.

Are you afraid of overspecializing? If you’re a developer who focuses mostly on web development, then take a step out of the norm and look into client app dev with WPF, make a game in XNA, or write a Windows Phone app! If you’re an IT pro who’s been siloed to focus on Exchange, you can start working with PowerShell for Exchange and then investigate other technologies that use PowerShell – such as SharePoint or Active Directory! Do something that you wouldn’t normally do, and make it a goal to learn at least one new technology a year, whether it applies to your job today or to possibly your career in the future!

PowerShell Not Your Father’s Command Line Part 15 of 31: ISE, ISE Baby…

Here’s hoping the PowerShell community doesn’t block me from their websites for my awful taste of music. 😉

Today’s topic is the ISE, the Integrated Scripting Environment. This PowerShell host application, written in WPF, is new as of PowerShell v2.0. In this post, we will look at some of my favorite features.

Panes

As one who writes script files more than just one-off commands, I like that the ISE has 3 panes – the Script Pane, the Command Pane, and the Output Pane. The order of these panes can be toggled from a menu or via keyboard shortcuts. Here are the basics of these panes:

  • Script Pane: This a pane dedicated to editing multi-line scripts. Some of the features I particularly am fond of with the Script Pane are syntax highlighting, debugging, and tab completion.
  • Command Pane: This is a pane dedicated to run commands on demand. Think of it as the console.
  • Output Pane: This is where the commands from the Command Pane and the scripts from the Script Pane output their results.

Keyboard Shortcuts

As a developer who prefers keyboard shortcuts rather than clicking buttons, I also am super happy that the shortcuts for running and debugging scripts in the ISE match up with keyboard shortcuts in Visual Studio. These are a few keyboard shortcuts that are the same:

  • F5 – Run
  • F9 – Toggle Breakpoint
  • F10 – Step Over
  • F11 – Step In
  • Shift + F11 – Step Out

Using the ISE as an Editor

In Matt’s post on profiles, he talked of editing the $profile file with notepad. For me, I tend to run the following command to the ise alias instead when I’m in the console:

ise $profile

The reason why I like the ISE for updating my profile files is because I have syntax highlighting, as seen below:
Sarah's console profile file in the scripts pane of the ISE

A Note on ISE Profiles

Applications that host PowerShell can implement any or all of the profiles. In my post on profiles, I noted that there were 4 console profiles. The ISE has 2 profiles of its own:

  • $profile, $profile.CurrentUserCurrentHost
  • $profile.AllUsersCurrentHost


This covers some of the basics of the ISE. If you want to learn more, you can run:

Get-Help about_Windows_PowerShell_ISE