Learn about Windows PowerShell
Summary: Discover Windows PowerShell cmdlets and modules in Windows Server 2012 R2 for networking.
Hey, Scripting Guy! I used to use netsh.exe to try to automate my server configurations. I can deal with it, but I heard that you can do a lot of this with Windows PowerShell in Windows Server 2012 R2. Do you know how I figure out which cmdlets to use?
Honorary Scripting Guy, Sean Kearney, is here. Today kicks off Windows PowerShell Network Week. I’m going to introduce a new and better way to manage networking in the Windows Server environment by using the network cmdlets in Windows Server 2012 R2.
You mentioned netsh.exe. I remember netsh.exe. I remember vividly not liking it. You could automate it, but it was difficult to find good examples of everyday use. I had to dig around online.
Having said that, there are scenarios where netsh.exe is still used. For example, netsh.exe is still one of the ways to list and remove wireless profiles. Pierre Roman from Microsoft Canada showed us this neat trick:
NETSH wlan show profiles
But there is so much more you can now do far easier in networking by using Windows PowerShell in Windows Server 2012 R2. Whether you are a new IT pro just getting your feet wet or a seasoned field specialist, Windows PowerShell makes the tasks far simpler and more consistent for your network needs.
So let’s take a quick look at how many modules are available to us to manage networking needs in Windows Powershell:
Get-Module *NET* -ListAvailable
Eleven modules just sitting there, itching to be used to make your day easier. This week I’ll try to touch on some of the more common networking needs and show you how they can be done in the Windows Server 2012 R2 environment.
That little voice in me is wondering (for trivia’s sake), “How many cmdlets do we have available.”
Oh just for fun, we’ll find out:
Get-Command –Module *NET*
I tried to count them all as they scrolled past me, but even with five espressos, I couldn’t read that fast. (No really, I couldn’t!) So I let Windows PowerShell do the counting for me:
(Get-Command –Module *NET* ).count
I had to pick my eyeballs off the ground and wipe them off as I saw the number: 283! I mouthed aloud as a large puddle of drool formed on my desk, “Oh, this is going to be a fun week!”
So where do we start? Let’s do something simple and try to work out physical network adapters. So how would I go about trying to find a cmdlet that might have something do with adapters?
How about a simple Get-Command and simply ask!
Get-Command –Module *NET* -verb GET -noun *Adapter*
So it looks like trying to get network adapters is going to be easy. There is a whole pile of cmdlets written for that task alone. In addition, I can see the module names seem to reflect their tasks very well.
What does that mean?
I should be able to look at the module name and determine its purpose easily.
For example, NetAdapter handles requests about my network adapters. So perhaps the NetSecurity might have something to do with the firewall? I can easily pull down the cmdlets for NetSecurity and look:
Get-Command –Module NetSecurity
Looks like it does!
All this means that I simply need to think about what I’m going to need to do, find the appropriate module, and determine whether I’m going to Get or Set or Remove network information. We can plug this into Get-Command to suggest the appropriate cmdlets!
BP, come back tomorrow and we’ll play with a scenario in which we start to use the network cmdlets in action.
I invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then remember eat your cmdlets each and every day with a taste dash of creativity.
Sean Kearney, Windows PowerShell MVP, Honorary Scripting Guy