Tag Archives: PowerShell

Happy International PowerShell User Group Day!

Today, techies throughout the world are celebrating the awesomeness of PowerShell with International PowerShell User Group Day.  Some people are quick to dismiss it as an IT admin tool, but there are other people besides sysadmins who use PowerShell.  I can think of a SharePoint guy, a few SQL Server guys, and yes, even developers, who have embraced the power of PowerShell.

PowerShell Community Groups

There are user groups throughout the world to celebrate discoveries and share scripts done in PowerShell.  Yes, I did say “throughout the world”.  Let’s take a look at the list at PowerShellGroups.org.  Besides the US, I see groups in Denmark, Egypt, UK, Norway, India, and Singapore.  For those who do not have a user group close, there’s even a Virtual Group!

Sponsors of Today’s Celebration

Today’s celebration of PowerShell user groups has been talked about throughout the PowerShell community.  They’ve even gotten some familiar faces in the community to sponsor the day.  So let’s thank these companies for helping make today a success:

Special Meetings

There are special meetings today for user groups to tune into presentations by PowerShell MVP/author/columnist Don Jones, Microsoft’s Hey Scripting Guy! Ed Wilson, and many others.  Special thanks to Interface Technical Training for providing the Remote Live platform for delivering this talk.   The meetings themselves will be broadcast at:

  • 1st broadcast – 12:00 PDT (19:00 Zulu)
  • 2nd broadcast – 15:00 PDT (22:00 Zulu)
  • 3rd broadcast – 18:00 PDT (01:00 Zulu)

To catch these presentations, check out your local PowerShell user group.

Happy International PowerShell User Group Day!

Intro to PowerShell @ MIGANG – Notes from 2/15 Presentation

On February 15, I was privileged to speak at MIGANG on PowerShell. As true with most of my PowerShell presentations, there are no PowerPoint slides for this presentation, just a custom module that has my comments on various topics.

The custom module is a manifest module, as I generated a PSD1 file for the module. However, if you remove the PSD1 file, the module is then considered to be a script module, as was covered in the talk.

To give you some background, my $profile has the following setup:

Set-Alias alias Set-Alias

function Get-Home{
    cd ~
}

$PSModulePath = $env:psmodulepath

I use the alias example because it disturbs me that there are some Linux commands that are already aliased, but the obvious alias alias was left out.

The function Get-Home is referenced in one of my help files. There’s a story behind this one. Again, this goes back to my Linux/Unix background. While Matt and I were working on our book, he had an example of a custom function that would get the user’s home directory. He used some long, convoluted path after the cd command. Of course, I had to come back and explain to him what the ~ meant, as I used to type cd ~ a lot when I spent time in the Unix labs on campus in my college days. It wouldn’t be until later on, as I was preparing for this talk, that I found the ~ explained in a PowerShell help file. (It’s in Example 1 of the help text for Resolve-Path.)

Finally, I included the $PSModulePath variable for two reasons. One, there’s improper documentation that this variable is a pre-defined variable. There are community comments that point out this flaw. The other reason is so that I can use the environment variables as a good segue into the providers topic.

I noted that I was not really going to get into covering creating custom providers, as there is a lot of detail behind that. However, if you want to talk providers, Oisin Grehan is a PowerShell provider master. He is also the guy behind the PowerShell Script Provider, to allow writing PowerShell providers in PowerShell scripting language and not necessarily in C#.

The other recommendation that was mentioned was to use the #PowerShell hashtag on Twitter, as there are many awesome PowerShell MVPs and notable people who work with it who are gratiously answering questions and helping as needed, providing direction for learning more on PowerShell.

You can download the custom MIGANG-Feb2012 module here.

If you have PowerShell already installed, then here are the steps for using the module:

  1. Start PowerShell (ISE or console).
  2. Extract the zip file into one of the Modules folders in $env:PSModulePath.
    Mine has the following values:

    C:\Users\sdutkiewicz\Documents\WindowsPowerShell\Modules;
    C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

    The best command I’ve found to see this in PowerShell is:

    dir env:PSModulePath | select Value

  3. Run the following command:

    Import-Module MIGANG-Feb2012

  4. Getting started with the module, run: Get-Help about_KeyTerms for more information.

I briefly ran through creating custom cmdlets in C#. In our book, I wrote about cmdlets to work with the Windows 7 Libraries feature – the feature that deals with Documents, Music, Video, Pictures, Contacts, and Downloads. The code that I used for that part will most likely be included in supplemental materials for our book. You can order the Automating Microsoft® Windows Server 2008 R2 Administration with Windows® PowerShell 2.0 book through a variety of vendors.

I had a lot of fun presenting to such a lively crowd, and I especially enjoyed talking with others at Copper Canyon afterwards! Thanks to all who came out for it!

Using StudioShell to generate WiX XML

I have to say it – after seeing Jim Christopher‘s StudioShell talk at devLink this past year, I think it’s been my most favorite Visual Studio tool so far.  I get to use my PowerShell knowledge to help script stuff out, saving my teammates a ton of work.  Today, we added about 10 new pages to one of our client’s sites and had to update a WiX installer.  Recognizing patterns and an opportunity for PowerShell, I just had to use StudioShell to eliminate the tediousness of generating the XML code manually.

Background

We have a Visual Studio 2010 solution with numerous projects – class libraries, WiX installers, and at least one web application.  One of the annoyances we have on our team is maintaining the WiX files every time we update a page, in order to make sure our pages get deployed properly.  So imagine our frustration today, after adding about 10 pages of content to our web application, we realized that we had to update our WiX installer for the website.

For those not familiar with WiX – Windows Installer XML (WiX) is what’s used in creating MSI files from XML.  You can use the WiX toolset to help you maintain these packages.  The WiX toolset documentation is available on SourceForge.  Every time we need to add a file to the server, we have to update our WiX wxs file.  Syntax for that looks something like this:

<File Id="SampleFile.aspx" Name="SampleFile.aspx" Source="$(var.OurSamplePath)\Subfolder\SampleFile.aspx" />

Problem and Solution

Our problem was that we needed to create that line for 10 new ASPX files.  Sure, we could have borrowed a line from one of the files already in the directory, copied and pasted it 10 times, and then manally search-and-replaced each of these instances.  But even that takes a long time.  Knowing what I did with what tools I had available, this is how I saw it.  That XML above pretty much boiled down to this for me:

<File Id="{0}" Name="{0}" Source="$(var.OurSamplePath)\Subfolder\{0}" />

I saw that pattern and realized I could turn that into a string and pass it the names of the files.  I also realized that I could use StudioShell to navigate through my project’s structure to get a list of the new files – which happened to be all of the ASPX files in a particular director and output them into this XML.  My StudioShell commands looked something like this:

cd DTE:
cd solution\projects\ProjectName\SomeSubFolder
dir *.aspx | % { "<File Id=`"{0}`" Name=`"{0}`" Source=`"`$(var.OurSamplePath)\Subfolder\{0}`" />" -f $_.Name }

The StudioShell output looked something like this:

<File Id="AgeGroups.aspx" Name="AgeGroups.aspx"
Source="$(var.OurSamplePath)\Subfolder\AgeGroups.aspx" />
<File Id="Fees.aspx" Name="Fees.aspx"
Source="$(var.OurSamplePath)\Subfolder\Fees.aspx" />
<File Id="Home.aspx" Name="Home.aspx"
Source="$(var.OurSamplePath)\Subfolder\Home.aspx" />

What took me a few minutes to type the command, run, copy the output, and paste into the wxs file could have easily taken longer if I hadn’t had StudioShell.

Note: While I could have fired up PowerShell and navigated my code via the FileSystem provider (as the dir command and the string formatting are PowerShell), I preferred to use StudioShell because our projects in the solution were in different folders and having the DTE:\solution\projects navigation that StudioShell made it that much more easier and convenient to just do this work from within Visual Studio.

Conclusion

Once again, having StudioShell as part of my installed Visual Studio tools made it that much easier for me to script out a process and get the results I needed within a much shorter period of time than doing it manually.  If you haven’t checked out StudioShell yet, you can find it at http://studioshell.codeplex.com.

Ann Arbor Day of .NET 2011 Recap

Yesterday, I was up in Ann Arbor, Michigan for their Day of .NET event at Washtenaw Community College.  I wanted to thank some of the organizers – Jason Follas, Jay Harris, and Scott Zischerk – for making this happen.  I know how much work it takes to get one of these together, and without them, we wouldn’t have had an event in the first place.  Also thanks to the sponsors – Telerik, TechSmith, ComponentOne, and Applied Innovations – as they also made contributions to help make this a great event.

It was great to see so many of my friends yesterday, and it was great to see at least one speaker outside of the Heartland District.  I was glad to see David Hoerster made it out from Pittsburgh!  For me, I wanted to catch sessions that I’ve been meaning to catch for awhile or sessions that I could learn from to apply to my current projects.  Here’s what I caught yesterday.

Dealing with Data in a Mobile Application, presented by Jeff Fansler

In this presentation, Jeff talked about consuming data, storing data, and caching data.  We looked at sync vs. async and how those worked.  When it comes to storing data, Jeff mentioned three options – isolated storage, Sterling DB, and – now with Mango – SQL CE!  I was already familiar with isolated storage, since I’ve used it in my Silverlight apps.  However, I hadn’t seen examples of Sterling, and his example would have been a good guide for that.  I was a little bummed that there wasn’t a SQL CE example, as I have an app that I’m working on that would benefit from SQL CE.  But alas, I’ve got something new to learn!  The last thing Jeff covered was saving data – both on demand and as a background task.  Overall, I really enjoyed this talk and have a lot to take away from it.  If you were at AADODN and didn’t catch this, you can catch it again at CodeMash!

Going Independent, presented by Michael Eaton

As you may know, I have gone independent, as of August.  I’ve got a couple clients that I’m working on now, and I’m learning to balance my work demands and my life demands.  I caught this session at devLink this past August, and although I had already asked Mike for advice before this, I still learned a bit from it.  As he mentions – when you go independent, you typically aren’t 100% billable – you can’t really bill for invoicing, other accounting business, and other administrivia.  He also mentioned a bunch of other helpful tidbits for those getting started on going on their own.  Like he said in his presentation, the ideas he covers in his presentation are based on what he has experienced in this past decade, and each indie has a different story.  If you didn’t catch this session, it will be done as a PreCompiler at CodeMash!

Develop IT: Intro to PowerShell, presented by Sarah Dutkiewicz

I was asked by Jay Harris awhile back if I would consider submitting this talk to Ann Arbor Day of .NET, and since it’s my favorite talk to give, I was happy to oblige.  Once again, this session was for a packed room, with an interesting audience.  This time around, I didn’t speak to my help files as much as I have in the past.  However, I did continue to keep this slideless and work from a custom module.  You can download the module from http://qtlil.me/aadond2011ps.

I also managed to cut a little bit out so that I could mention Jim Christopher‘s StudioShell.  As a developer with a little bit of PowerShell background, you can make this tool work for you in ways you couldn’t imagine.  For example, we have a client who stored error messages in a class, but our business analysts wanted to maintain those messages.  Rather than manually creating the XML file that we had envisioned, I had one of my teammates show me what he was looking for format-wise, and I got it for him in a matter of minutes.  Most of the minutes were me waiting to install StudioShell in my VM – otherwise, with one line of code, I was able to extract the constant string variables’ names and values and put them into an XML file.

If you haven’t caught this presentation yet, I’ll be giving it in the Detroit, MI-area at MIGANG on February 15.  If you’re interested in hearing it at your user group, please contact me at sarah at codinggeekette dot com.

Stone Soup or Creating a Culture of Change, presented by James Bender

It was great to wind down from the conference with this session. Throughout this session, James talks of how to deal with change in a company.  One of my recent favorite phrases was near the beginning of this presentation – Change where you work or change where you work.  If things aren’t going the way you like, you can try implementing change in the workplace to  make things better.  For example, maybe you work at a company that seems to hesitate with developer training.  Rather than letting them slack in that department, you could encourage your teammates to learn by doing lunch’n'learns.  But let’s say that the company seems to be lacking in ways that you can’t change.  Then maybe it’s to change your work in terms of finding a new place to work.  This is one of many phrases and stories that James’ presentation suggests.  Unfortunately, he is retiring this talk for now.  But if you find yourself trying to initiate change in the workplace and have troubles, James is a good guy to talk with about that.

Conclusion

I unfortunately didn’t stay for the closing ceremony, as I needed to get on the road for a 3 hour ride back to Cleveland.  However, from what I’ve been able to experience, Ann Arbor Day of .NET once again turned out to be a great event, well worth the 6-hour total travel time.  I’m glad I drove up for it!  Thanks again to those who organized the event and made the event happen!

If you, my readers, haven’t had the chance to attend a Day of .NET event, you’re missing quite a bit.  Typically, for a small fee (approximately $10 nowadays), you can get a day’s worth of training from regional experts on a variety of topics.  It’s a great event to learn something new.  It’s also a great event for networking with those in the community, finding other people who have the same problems as you or who have had your problem and may have a solution.  You can always find more on Days of .NET at http://dayofdotnet.org/.  Hope to see you at one in the future!

devLINK 2011 Recap – Sadukie’s Tales, Part 3

Standing room only at 8am… what a way to wake up!  Thanks to all of you who attended my “Develop IT – Intro to PowerShell” talk at 8am.  It was great to share my love of PowerShell and how to get started with those who wanted to learn more.  We started at the basics and then looked at some PowerShell building blocks.  My second session was less attended, but those who were there asked questions that showed they were interested.  We looked at script versus binary versus manifest versus dynamic modules.  Code samples were written in both C# and PowerShell.  Thanks to all of you who attended, and especially thanks to those who left feedback.  I’ve read through the feedback and look forward to expanding on these talks.  As I mentioned, there are some great resources for working with PowerShell:

The music video that I kicked off both sessions with was Highway to PowerShell – Part IV – A New Hope, as performed by Sean Kearney, a.k.a. energizedtech on Twitter:

In the afternoon, I caught my friend Michael Eaton‘s “Going Independent” talks.  Since I’m just starting out on my own with Cleveland Tech Consulting, LLC, I wanted to hear it from him and others as to what are some things I may need to account for.  While I may have talked with some of my friends who are company owners and independent consultants, I still wanted to see what I may have missed.  I learned a lot about myself and my decisions for going forward, including trusting my instinct and not being afraid to walk away if something doesn’t seem right.

Since I left the hotel in a hurry that morning, I needed to take the evening off to bounce back from my rushed morning.  I caught dinner with a group of friends – including Jeff x 3 (Jeff Blankenburg, Jeff Fansler, and Jeff McWherter) and a few others – at The Terminal Brewhouse.  Pizza π Rolls and Mr. Frog’s Super Happy Fun Journey are both very tasty appetizers.

It was also great that Jeff McWherter brought some of his Gravity Works Design & Development employees with him to devLINK.  I really enjoyed hanging out with them!

After dinner, I spent some of the evening hanging out with friends and the rest just resting.  It’s been a great event so far, and I’m already eager to see what devLINK 2012 will have in store for us!

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!

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.