IT Training and Certification

Rubel Khan's Blog

Archive for the ‘PowerShell’ Category

Microsoft Learning Product Releases for July 18-31

Posted by Rubel Khan on July 28, 2010

1.       Microsoft Official Courses (MOC) are instructor-led training courses offered by our Certified Partners.  Not all classes will be offered by all partners.  Find a training center through Class Locator and see if they will be offering the course you need.

2.       Community Courses (CC) are instructor-led training courses offered by our Certified Partners wherein the content is authored by our learning community.

3.       General Availability for MOC and CC is dependent on our Certified Partners, but the earliest is Orderable Date + 7 days.

4.       Products with no link currently don’t have a URL – search for the course in the training catalog

 Microsoft Exchange Server 2010

Title Type RTM (MCT Availability) Orderable Date (MPN Availability) General Availability
Deploying Exchange Server 2010 E-Learning     7/23
Configuring Mailbox Servers in Exchange Server 2010 E-Learning     7/23
Managing Recipient Objects in Exchange Server 2010 E-Learning     7/23
Managing Client Access in Exchange Server 2010 E-Learning     7/23
Configuring Message Transport in Exchange Server 2010 E-Learning     7/23
Implementing Messaging Security in Exchange Server 2010 E-Learning     7/23
Implementing High Availability in Exchange Server 2010 E-Learning     7/23
Implementing Backup and Recovery in Exchange Server 2010 E-Learning     7/23
Configuring Messaging Policy and Compliance for Exchange Server 2010 E-Learning     7/23
Maintaining Exchange Server 2010 E-Learning     7/23
Deploying Exchange Server 2010 E-Learning     7/23
Managing Mailbox Servers and Recipients in Exchange Server 2010 E-Learning     7/23
Managing Client Access in Exchange Server 2010 E-Learning     7/23
Managing Message Transport and Security in Exchange Server 2010 E-Learning     7/23
Implementing High Availability and Disaster Recovery in Exchange Server 2010 E-Learning     7/23
Configuring Messaging Policy and Compliance in Exchange Server 2010 E-Learning     7/23
Introduction to Planning an Exchange Server 2010 Deployment E-Learning     7/23
Planning the Exchange Server 2010 Infrastructure Environment E-Learning     7/23
Planning and Deploying Client Access Services in Exchange Server 2010 E-Learning     7/23
Planning and Deploying Message Transport in Exchange Server 2010 E-Learning     7/23
Planning and Deploying Mailbox Services in Exchange Server 2010 E-Learning     7/23
Planning and Deploying Messaging Security in Exchange Server 2010 E-Learning     7/23
Planning and Deploying Messaging Compliance in Exchange Server 2010 E-Learning     7/23
Planning and Deploying High Availability in Exchange Server 2010 E-Learning     7/23
Planning and Implementing Disaster Recovery in Exchange Server 2010 E-Learning     7/23
Transitioning to Exchange Server 2010 E-Learning     7/23
Configuring, Managing and Troubleshooting Microsoft® Exchange Server 2010 (German, Japanese, French) MOC  7/30 8/16 (Japanese, French), 8/30 (German) 8/23 (Japanese, French), 9/6 (German)

 

Microsoft SharePoint Server 2010

Title Type RTM (MCT Availability) Orderable Date (MPN Availability) General Availability
What’s New in Microsoft® SharePoint® 2010 for IT Professionals E-Learning     7/21
TS: Microsoft SharePoint 2010, Configuring (German, French, Japanese, Portuguese (Brazil)) Exam     7/27, 9/30 (Portuguese(Brazil))

  

Microsoft Office 2010

Title Type RTM (MCT Availability) Orderable Date (MPN Availability) General Availability
Beginner Skills in Microsoft® Outlook® 2010 (Italian, French) MOC 7/19 8/2 8/9
What’s New in Microsoft® Office® 2010 MOC 7/28 8/11 8/18
Beginner Skills in Microsoft® PowerPoint® 2010 (Spanish, Japanese) MOC 7/28 8/11 8/18
Beginner Skills in Microsoft® Outlook® 2010 (German) MOC 7/28 8/11 8/18
Beginner Skills in Microsoft® PowerPoint® 2010 (German) MOC 7/28 8/11 8/18
Skills Training in Microsoft® SharePoint® Designer 2010 MOC 7/29 8/12 8/19
Beginner Skills Training in Microsoft® Visio® 2010 MOC 7/29 8/12 8/19
Microsoft® SharePoint® Designer 2010 Part 1 – Setting up a New Site MOC 7/29 8/12 8/19
Microsoft® SharePoint® Designer 2010 Part 2 – Workflows MOC 7/29 8/12 8/19
Microsoft® SharePoint® Designer 2010 Part 3 – Content Types MOC 7/29 8/12 8/19
Microsoft® SharePoint® Designer 2010 Part 4 – Integrating Business Data MOC 7/29 8/12 8/19
What’s New in Microsoft® Access® 2010 (German, Spanish, Japanese) E-Learning     Now
What’s New in Microsoft® Publisher 2010 (German, Spanish, Japanese) E-Learning     Now
What’s New in Microsoft® Visio® 2010 (German, Spanish, Japanese) E-Learning     Now
Skills Training in Microsoft® Outlook® 2010 (German, Spanish, Japanese) E-Learning     7/28
Skills Training in Microsoft® Word 2010 (German, Spanish, Japanese) E-Learning     7/28
Skills Training in Microsoft® Excel® 2010 (Spanish) E-Learning     7/28

 

 Microsoft Essential Business Server

Title Type RTM (MCT Availability) Orderable Date (MPN Availability) General Availability
Configuring, Implementing, and Managing Windows® Essential Business Server 2008 E-Learning     7/28

 

 Microsoft Windows Server 2008

Title Type RTM (MCT Availability) Orderable Date (MPN Availability) General Availability
Implementing and Managing Microsoft® Server Virtualization MOC 7/20 8/3 8/10
Fundamentals of Windows Server® 2008 Network and Applications Infrastructure (Spanish) MOC 7/30 8/13 8/20
Configuring and Troubleshooting Windows Server® 2008 Active Directory® Domain Services (Spanish) MOC 7/30 8/13 8/20
Configuring and Troubleshooting Internet Information Services in Windows Server® 2008 (Spanish) MOC 7/30 8/13 8/20

Source: Born to Learn

Posted in ASP .NET, Azure, Bing, BizTalk Server, Business Intelligence, C#, Certification, Cloud Computing, Dynamics AX, Dynamics CRM, Dynamics GP, Dynamics NAV, E-Book, E-Learning, EPM, Exam, Exchange Server, Expression, Forefront, MCAD, MCITP, MCM, MCPD, MCSA, MCSE, MCT, MCTS, Microsoft, Microsoft Certifications, Microsoft Press, MOC, MOS, MTA, Novell, Office 2010, Operations Framework (MOF), PerformancePoint Server, PowerShell, Project Server, SCCM, Security, Server 2008, SharePoint, Silverlight, SQL Server, SSIS, System Center, Virtualization, Visual Basic, Visual C++, Visual Studio (.NET), Windows, Windows 7, Windows Live, Windows Phone, Windows Server, Windows Vista, Windows XP | Leave a Comment »

Run IT on a Virtual Hard Disk – Test Drive Program

Posted by Rubel Khan on March 9, 2010

The Microsoft Virtual Hard Disk (VHD) format is the common virtualization file format that provides a uniform product support system, and provides more seamless manageability, security, reliability and cost-efficiency for customers.

Featured VHDs

Using the power of virtualization, you can quickly evaluate Microsoft and partner solutions through a series of pre-configured virtual hard disks (VHDs). You can download the VHDs and evaluate them for free in your own environment without the need for dedicated servers or complex installations.

  • Windows Server 2008 R2 Enterprise Edition x64 (Full Install)
    You will have the opportunity to try the new and improved features and functionality of Windows Server 2008 R2 free for 180 days. Windows Server 2008 R2 builds on the foundation of Windows Server 2008, offering new virtualization tools, Web resources, management enhancements, and Windows 7 integration. Tools such as Internet Information Services (IIS) version 7.5, updated Server Manager, Hyper-V platforms and Windows PowerShell version 2.0 combine to provide greater control, increased efficiency and the ability to react to front-line business needs faster than ever before.
  • Microsoft Windows 7 Enterprise
    Windows 7 has many new features and file management enhancements — like Jump Lists and improved taskbar previews — to help speed you through everyday tasks. Windows 7 is designed for faster and more reliable performance. With 64-bit support, you can take full advantage of the latest generation of powerful PCs and processors. New features like HomeGroup, an updated Windows Media Center and Windows Touch make new things possible.
  • Exchange Server 2010 for Windows Server 2008
    Evaluate the new capabilities of Exchange Server 2010, which helps you achieve new levels of reliability and performance and delivers features that help to simplify your administration, protect your communications, and delight your users by meeting their demands for greater business mobility.

VHDs by Product

Learn More About VHDs

VHD Product Overview
Learn about the VHD Test Drive Program, get an introduction to virtual machine technology, and read about key features and benefits of using VHDs in this overview.
Frequently Asked Questions about VHDs
Find general information about using VHDs, virtual machine technology, requirements, and more in the VHD FAQ.
Become a VHD Test Drive Partner
The Microsoft VHD Test Drive Program provides Microsoft’s partners a convenient and simplified process for creation of application images, facilitates its widespread distribution by making it available as a free download and enables accelerated evaluation and testing of these applications by customers.
VHD Image Format Specifications
With the VHD format now available as a freely available specification, Microsoft is contributing to the continued expansion of the virtualization market by fostering interoperability among all commercial software solutions, including open source.

Posted in Exchange Server, Hyper-V, PowerShell, Server 2008, Virtual Hard Disk (VHD), Windows 7 | Tagged: , | Leave a Comment »

Windows PowerShell Quick Reference (Download)

Posted by Rubel Khan on March 7, 2010

Overview: Quick reference guide to commonly-used Windows PowerShell commands. For best results, open the file in Microsoft Word, print the contents to legal-sized paper (8 inches by 14 inches), and fold the resulting printout in half, making a four-page booklet.

Posted in PowerShell | Tagged: | Leave a Comment »

Hey, Scripting Guy! How Can I Learn Windows PowerShell? (From Scripting Guy! Blog)

Posted by Rubel Khan on September 7, 2009

Hey, Scripting Guy! Question Hey, Scripting Guy! I recently ran across the Hey, Scripting Guy! Blog and have been fascinated by the different things you can do with scripts. I now think I can use them to make my life easier as a network administrator. So here is my question: How can I learn Windows PowerShell? I know I can keep reading the Hey, Scripting Guy! Blog, and I will learn things but would like to come up to speed more quickly. Do you have any suggestions?

– TW

Hey, Scripting Guy! Answer Hello TW,

Microsoft Scripting Guy Ed Wilson here. Let’s turn the hands of time back a few years, back to a time before I became a Microsoft Scripting Guy, back before I was a Microsoft employee, back before I was a consultant for a Microsoft Solutions Provider, back to a time when I was just starting my career as an IT pro, and I was working on my Microsoft Certified Systems Engineer—for Windows NT 3.51. There was the Internet, but the World Wide Web was still in its infancy. The Internet was mostly populated by things called Archie servers and Gopher servers. One day, I stumbled across a posting for an e-mail list that was powered by a program called LISTSERV that was dedicated to people who were studying for their MCSE. At first I mostly lurked on the list, reading others questions and savoring the responses. After a few weeks, I gathered up the courage to ask my first question. I did not want to appear to be lazy or stupid, so I looked everywhere I could think of to try to find an answer to the question myself, but the solution was not forthcoming. So I wrote the question, looked at it, edited it, and then finally posted it. Anxiously for the remainder of the evening, I went back to my computer, logged on, turned on my modem, loaded the Trumpet winsock application, and listened to the eerie beeping, squeaking, and other oscillating tones that were at last followed by a cheerful beep. I then opened up my e-mail program, and waited for messages to slowly fill my inbox. There it was—one of the last messages was the answer to my question.

The next day when I arrived home from work, I ran to my study, turned on my computer, and once again performed the ritual of the modem dance. This time I was determined to find a question I could answer. I chose one that I thought I knew the answer to, typed up my reply, and posted. When others on the list replied that my answer was correct, I was hooked. After that, there was no stopping me. I made a point of trying to answer one question a night. By the time I took my first MCSE exam—which I passed by the way—I found I had learned more by helping others than I had learned from my own reading and studying.

These days, of course, you do not have to mess with choosing and configuring your own TCP/IP protocol stack, and in most parts of the world (but unfortunately not all parts of the world) modems are relegated to faxing, out-of-band (OOB) management, and certain call-home applications. A few e-mail lists might still be in existence, but the MCSE list that was once the center of my certification world has gone the way of the Gopher server, the Archie server, and other pieces of that ancient era. Only my 9600 bit/s modem remains from those heady days of experimentation and learning.

But, TW, you asked about learning Windows PowerShell scripting and coming up to speed quickly. A great place for you start is with our Learn page. From there you will find links to webcasts, virtual labs, technology pages, and books. A great book to get started learning Windows PowerShell is Microsoft Press Windows PowerShell Step by Step. It has lots of good script examples and step-by-step exercises that are organized in such a way that it will help you to come up to speed quickly.

On the TechNet Script Center, you can also participate on the Official Scripting Guys Forum, which you can get to by clicking the Forums tab on our home page. Sign in with your Windows Live ID and that is all that is needed to post questions and answers. Your Windows Live ID also gives you the ability to upload scripts to the new TechNet Script Center Gallery, which you will most certainly want to do when you have written your first real script!

This week we are looking at questions that have been posted to the Official Scripting Guys Forum. This user forum is a great place to ask questions related to VBScript or Windows PowerShell. It is also an excellent resource to learn scripting by either reading answers to others questions or by becoming involved in discussions through posting answers. In addition to being a learning resource, the forum is also a fun place to interact with people from around the world who have an interest in scripting. The Official Scripting Guys Forum is free. If you wish to post a question or propose an answer to a question, you will need to log in with your Windows Live ID.

Today, I was at the Official Scripting Guys Forum reviewing some of the questions that had been asked, posting answers, and in general just hanging out when I ran across a pretty interesting question: How can I start a new instance of Windows PowerShell from a script and change the window title of the Windows PowerShell console: The thread is seen here:

Image of the forum thread 

What is interesting in this particular thread are some of the ideas that are suggested. The question involves starting a new Windows PowerShell console from within a script, but the person asking the question also wants to pass an argument to the script, and then change the title that is displayed at the top of the Windows PowerShell console. This question and the answer would apply to both Windows PowerShell 2.0 and Windows PowerShell 1.0.

TW, let’s play with the first solution that was offered by one of our MVPs.

Suppose you have a Windows PowerShell script called Title.ps1 that displays a message that says hello with the person’s name that is passed as an argument. This script is seen here:

Title.ps1

“hello $args”

You are inside a Windows PowerShell console and want to start the script in a new Windows PowerShell console, change the console title to be the name of your computer, and pass an argument to the newly started script. The command seen here is one logical command, meaning it can be cut and pasted directly into the Windows PowerShell console as is, or you could type it as one long command and let it wrap. The backtick character (`) is used for line continuation, and you would not need to type it if you were typing the commands in the Windows PowerShell console and letting it wrap. The semicolon is the new command character, and it is used to introduce a new logical command line. You would use it when typing in the Windows PowerShell console. The Windows PowerShell command is seen here:

cmd /c start powershell -NoExit -Command `

{$Host.UI.RawUI.WindowTitle = “$env:computername”;

c:\fso\title.ps1 ‘mred’}

The above command starts a new instance of PowerShell.exe, and it uses the –NoExit switch to cause the newly opened Windows PowerShell console to not close. The –Command parameter passes a Windows PowerShell script block that is a regular Windows PowerShell command like you would type directly into a Windows PowerShell console. The $Host.UI.RawUI.WindowTitle exposes the title property of the Windows PowerShell console. The $env:computername retrieves the name of the computer from the environmental drive.

When you cut and paste the command above, you see double arrows at the beginning of each line. This indicates that you have not yet typed a complete command, and Windows PowerShell is allowing you to continue your typing. It is added automatically because of the use of the backtick character at the end of the first line. You must press ENTER again to cause the command to be executed. This is seen here:

Image of incomplete command

When the command runs, you will see another Windows PowerShell console open. It will run the script and display the host name in the title window. This is seen here:

Image of host name in title window

As for copying and pasting, there are two ways to do it. I prefer to paste in the Windows PowerShell console by right-clicking with my mouse after I have pasted something onto the clipboard. Some people like to use the mouse and access the shortcuts menu:

Image of one way to paste in Windows PowerShell console 

You can use this same technique from within the Scheduled Task tool, or from the Start/Run option. You will need to modify the command a little; instead of using the cmd /start option, you substitute the command PowerShell –NoExit. The revised command needs to be a single line, and I use Notepad to keep track of the command and the changes to the command. This is seen here:

PowerShell -NoExit -Command &{$Host.UI.RawUI.WindowTitle = “$env:computername”; c:\fso\title.ps1 ‘mred’}

The above suggestion was in fact my own contribution to the conversation as it was progressing over at the Official Scripting Guys Forum. As I stated earlier, it is fun to become involved in the ongoing threads. It gives you something to look forward to: kind of like the weekend, but more fun.

TW, this should give you something to think about in your quest to learn Windows PowerShell. I highly advise you get involved with the Official Scripting Guys Forum because you really will learn a lot—at least it worked for me. Join us tomorrow as Scripting Guys Forum Week continues.

If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, shoot us an e-mail at scripter@microsoft.com or post your questions to the Official Scripting Guys Forum. See you tomorrow. Until then, keep on scripting.

Ed Wilson and Craig Liebendorfer, Scripting Guys

Posted in PowerShell | Tagged: | Leave a Comment »

Windows PowerShell Stay Seated! – Don Jones

Posted by Rubel Khan on August 6, 2009

I’ve always been frustrated by the dual message that sometimes comes out of Microsoft regarding server management: On the one hand, we’re rightly told to install management tools on our own client computers and to use those tools to manage our servers. We’re not supposed to go into the data center, and even using Remote Desktop is technically cheating because it’s basically just going into the data center without taking the walk. On the other hand, however, there are many server-management tasks that can’t be performed easily using existing remote tools—changing IP addresses or anything else with network configuration, for instance.
Windows PowerShell Q&A
Q Can a Windows PowerShell script be used as a logon script?
A Yes, but there might not be any point in doing so. You can’t just drag the script into a Group Policy object (GPO) in the way that you can a VBScript file. Instead, you have to basically create a batch file the runs Powershell.exe, passing the command-line parameter that tells it what script to execute. It’s awkward. You also have to install Windows PowerShell on every computer where that logon script will run. In the end, keep in mind that Windows PowerShell is a bit more self-contained than VBScript or the Cmd.exe shell. For example, mapping a drive using the New-PSDrive cmdlet won’t affect Windows Explorer—you’d have to fall back on the Net Use command to actually map a drive in Windows, and if you’re going to do that why not just use a traditional batch file, which is easier to include in a GPO?
 
Q Can Windows PowerShell scripts be scheduled?
A Absolutely. You’ll actually schedule PowerShell.exe (which is located in your %systemroot% folder, under /WindowsPowerShell), and give it a command-line parameter specifying the script you want it to execute. Be sure that the scheduled task is set up to utilize a user account that has the necessary permissions to do whatever the script does, and make sure the shell execution policy is configured to allow script execution (I prefer the AllSigned policy myself, which means your script will need to be digitally signed; run “Help about_signing” in the shell for details on this).
Q Is there an easy way to work with file and folder permissions in Windows PowerShell?
A Sure. You’ve got the Get-ACL and Set-ACL commands, to start with—Get-ACL is great if all you need to do is report on permissions. Frankly, using these commands to actually change permissions is impractical—Windows’ permissions are pretty complicated beasts, and the programming you have to do to set access control lists (ACLs) is equally complicated. But who says you have to use cmdlets? The shell is great at running more traditional command-line tools, and the various iterations of Cacls.exe (including ones like Dsacls for Active Directory) work great from within Windows PowerShell. I always use them when I need to modify or set file and folder permissions.
Setting up a new Server Core installation is another excellent example. Adding roles, configuring the network, even activating Windows must all be done from a local console window or via Remote Desktop, using command-line tools. What tools currently exist are either custom-written point solutions that handle a single task or solutions that require expertise with Windows Management Instrumentation (WMI). I like WMI, but frankly, it’s too complex for most administrators to spend a lot of time learning, and so it often goes unused.
Windows PowerShell has promised to make all of this easier—by making WMI a bit easier to handle, but more importantly, by wrapping up administrative tasks into easier-to-use cmdlets that correspond roughly with the command-line utilities we’ve used for years. The shell’s problem is that, aside from WMI, it’s essentially a local shell. Many of its core operating system-configuration cmdlets don’t provide any support for contacting a remote computer. The shell also doesn’t solve one of WMI’s more egregious problems: its use of Remote Procedure Calls (RPCs) for remote connectivity. RPCs are a hassle in environments that use local firewalls (and who doesn’t these days?), often making WMI unusable for any kind of remote management.

 

The Solution
Microsoft has been aware of these shortcomings for quite a while, but it’s taken some time for all the necessary fixes to line up in a single product. That product is Windows PowerShell v2, which includes a new version of Windows Remote Management (WRM). Both will ship for the first time in Windows 7 and Windows Server 2008 R2, and both will be pre-installed on those operating systems by default.
The technologies will also be made available for older versions of Windows, possibly as far back as Windows XP. But as of this writing, no official announcement has been made about exactly which older operating systems will be supported (the older the OS, the more difficult Microsoft’s task, because older versions may lack some of the necessary core supporting technologies).
WinRM is really the key technology that makes all this possible. It’s a Microsoft implementation of WS-MAN, or Web Services for Management, and as the name implies, it uses HTTP and HTTPS to communicate, which means that it’s easy to get the traffic through a firewall. Unlike RPCs, which start on a single well-known point and then move their conversation to a randomly chosen port, HTTP and HTTPS utilize a single port—80 and 443 by default, but configurable if you don’t like those. WinRM allows many different applications to “listen” for incoming management connections, and Windows PowerShell v2 is one application capable of doing so. (Personally, I think WMI might eventually migrate to use WinRM.)
Essentially, you sit on your client computer and ask it to make a shell connection to a remote computer. That activates WinRM on the remote computer, which in turn spins up an instance of Windows PowerShell v2 on the remote computer. That instance of the shell is capable of running your commands and delivering the results back to your computer.

 

See It in Action
The public beta releases of Windows 7 were the first time the world at large could try this out: Open a Windows PowerShell session on the server—or on multiple servers—and run Enable-PSRemoting to configure WinRM and start the WinRM service. Then, go to your client computer—also running Windows PowerShell v2—and run $session = New-PSSession computername, providing the name of the server you just configured for remoting. The New-PSSession cmdlet can also accept alternate credentials, if needed, and can be told to use non-standard ports if that’s what you’ve configured.
If you see a lengthy error message like the one shown in Figure 1, it’s because of the way WinRM authenticates. It uses Kerberos by default, but in a non-domain environment (like the one on the lab computer pictured), Kerberos isn’t an option. When Kerberos isn’t available, WinRM demands the use of the HTTPS transport, which requires that an SSL certificate be installed on the server computer. This is done to provide mutual authentication between you and the server so that you know you’re connected to the machine you wanted. Even specifying Basic or Digest authentication in the –auth parameter won’t help, because WinRM wants to use HTTPS to encrypt that traffic. The easiest solution? Be in an Active Directory domain!

Figure 1 A lengthy error message like this one may occur because of the way WinRM authenticates.
With your session activated, you’re ready to begin using it. Enter-PSSession $session will connect you, live, to the remote server. Magically, you’re typing in its instance of Windows PowerShell. Commands run interactively and you see the results immediately—not unlike SSH or similar technologies often used on UNIX computers.
Windows PowerShell even does some default encryption, so if you’re not using HTTPS, you’re still pretty safe from eavesdroppers. Run Exit-PSSession to detach from the remote console and return to your local console. The shell prompt even changes when you’re connected to a remote computer, to remind you where you are.

 

One-to-Many Remoting
Being able to run commands on one computer is great, but how often do you need to do one thing on one server? More commonly, I find I need to run a command, or a set of commands, on a whole bunch of computers. What we’ve used so far in Windows PowerShell v1 is called one-to-one (1:1) remoting, meaning a single administrator managing a single remote computer. But the shell also offers one-to-many (1:n) remoting, where a single administrator can manage multiple computers. The trick is in the –computerName parameter of New-PSSession.
Let me repeat my earlier command, but this time I’ll actually spell out the parameter rather than letting the shell assume it: New-PSSession –computerName computer. Because –computerName is a positional parameter, I didn’t need to specify the actual parameter name earlier, but doing so now will make this trick easier to understand: $sessions = New-PSSession –computerName (Get-Content c:\names.txt). Assuming that the C:\names.txt file contains a list of computer names, one computer name per line, then the shell will create a remote session to each of them, storing the whole list of sessions in the $sessions variable.
By default, the sessions are created using whatever credentials Windows PowerShell itself is running under—so, either my logon account or an account I used with RunAs when starting the shell. A word of caution: If you have User Account Control (UAC) enabled, be sure to explicitly start the shell “as Administrator” by right-clicking its icon. Alternately, you can specify a different username for the sessions by using the command’s –credential parameter.
Once you have this collection of commands, you can continue to work with them in the 1:1 fashion: Enter-PSSession $sessions[0] will connect you to the first computer’s shell instance, for example. But the real power is in running a command against all of them at once: Invoke-Command –scriptblock { ipconfig } 0 –session $sessions. That runs the Ipconfig command on every computer to which you’ve connected a session, and brings the results back to your computer. It will actually connect to the computers in parallel, up to 32 at a time; you can change that parallel execution throttle by using the –throttlelimit parameter.

 

Put It Out of Your Mind
Of course, sometimes you’ll fire off commands that take a while to run, and you might not want to sit around waiting for everything to complete. In such cases, why not let the shell keep working in the background? Just add the –AsJob parameter to Invoke-Command, and the shell will create a background job.
Remember that your copy of the shell isn’t really doing that much work; the commands you’ve specified are being executed on remote instances of Windows PowerShell. Your shell is just waiting for them all to finish, and collecting the results they send back. Those results are stored as part of the job. Run Get-Job to see all current jobs and their status (whether they’re still running, for example). Use Receive-Job to grab the results out of a completed job. So it all might look like this:

$sessions = New-PSSession –computerName (Get-Content c:\names.txt)
$job = Invoke-Command –scriptblock { your command(s) } –AsJob
Get-Job (to check the status)
$results = Receive-Job $job

You can then display $results, filter it, sort it, and so forth. Each result will have information attached to help you see which computer it came from. I’ll discuss background jobs (which can even have sub-jobs that you have to deal with) in a future article.

 

It’s Remote Management, New-School Style
Forget the old-school way of “remote” management that involved hiking to the data center or using a Remote Desktop “cheat.” Windows PowerShell v2′s remoting features are a powerful and simple way to run commands—any commands—on remote computers. Although my personal focus is on server management, these same techniques are great for desktop management tasks, as well, which is one reason why Windows PowerShell v2 is pre-installed on Windows 7 as well as Windows Server 2008 R2.

 

Don Jones is a co-founder of Concentrated Technology, where he blogs weekly about Windows PowerShell, SQL Server, App-V and other topics. Contact him through his Web site.

Posted in PowerShell | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: