Oliver Script: A Holiday Tale–Part 3


Summary: Oliver finishes computer school, gets his first real job, and uses Windows PowerShell remoting.

Note This is the third post in a series. To catch up, read:

It is the beginning of a new day for Oliver: computer school! Learning actual higher-end technology. Oliver was about to fall over as he walked into the institute. He could actually smell the ozone of the technology burning in the air.

As it turns out, it was actually a power cord burning behind a terminal. Oliver quickly reported the incident to his instructor, Mr. Beadle, who quickly dispatched Oliver with a roll of electrical tape to repair the issue immediately.

As odd as his instructor was, Oliver rapidly tore through his course to grant himself a diploma as a LAN administrator. The course was to take nine months, and the wee lad finished it in two!

“Ha! We’ll show you challenges!” Mr. Beadle shoved a mass of books at Oliver to force him to learn all that was needed to become an MCSE. “Trying to show us up? Cram this in to your head!” he cackled as he spun about.

However, challenges were something Oliver took to quite readily. All the knowledge lay before him ready to be consumed like a fine Thanksgiving feast! His eyes scanned left and right, pulling the information in. With three months remaining in the course, he had finished the MCSE courseware.

Disgusted, Mr. Beadle cast training for various computer languages, including Assembler, at Oliver. He included an additional challenge to kill off Oliver's hopes. “Pass all of these tests and complete your MCSE certifications, or we’ll not hand you your diplomas for any of this! Jobless you’ll be! HA!”

For a moment, Oliver nearly broke into tears. So close and yet so far. He had be told that the exams for the MCSE were the most difficult. He would need field experience to pass them. Yet his dreams carried him forth.

He tore through the courseware and passed all the school exams. At the same time, he was diving into every piece of material he could muster about the MCSE. He even managed to scrape together some money and rent a laptop to create a complete virtual network infrastructure with Hyper-V in Windows 8.1.

The time came. All the exams were scheduled in one day. Oliver’s head spun with technology, and he couldn’t even muster enough English to ask for a coffee at the local shop. He was a human CPU.

Days end occurred. All Oliver could remember was staring at the final results. The MCP, MCSA, and MCSE were his to behold. Even if Mr. Beadle refused his diplomas, these would and carry him to a future!

Mr. Beadle, as sadistic as he was, realized what a gifted individual Oliver was. He handed Oliver a pile of diplomas and certificates a mile high. Interviews began, including one with Microsoft, which is always looking for raw talent. Email address with names starting with “v-“ were handed to Oliver, but he would have to fly himself to Seattle.

For a moment, he was torn. This was an opportunity to never miss. A tear fell to the floor. “Microsoft thinks I’m one of them…” However, with no funds currently available, he’d need to find a way to work to get a flight and hotel. Being Canadian, he would even have to arrange to get a passport.

But as luck would have it, an interviewer local to his area was looking for a new MCSE who was willing to learn from the bottom. Oliver dived at the chance and accepted their job offer.

He immediately began working on site. This was a large Canadian company with an amazing cross section of technology. As the new fellow, he was tasked with imaging workstations and handling service desk calls.

The Tier 3 support staff in charge of servers noticed that he was an MCSE. “Have you ever heard of Windows PowerShell?” they asked him. “We’ve been trying to find an easier way to manage automation throughout the environment. We thought that you might know how—being fresh from school.”

Oliver remembered Windows PowerShell, of course! It was his first foray into automation. He had learned it in high school and used it to save his neighbor’s photos!

“Our challenge,” they offered the young fellow, “is to easily run the same script on our remote servers running Windows Server 2012 R2. We also need to manage the Active Directory servers from user workstations without installing the RSAT tools locally.”

Oliver though about his training. This sounded like an ideal scenario for a feature called “Windows PowerShell remoting.”

The first problem the server team wanted to address was that they needed to occasionally turn features on and off in the development environments. “Normally, we have to remote into the machine, but the problem we’ve encountered is that we sometimes inadvertently shut down a machine when we log off.”

Oliver sat down and showed them a basic feature of Windows PowerShell remoting: how to enable and work with an interactive session. "It is very much like a Telnet prompt works," he told them. He first used the New-PSsession cmdlet to dial a connection to the remote server, DevSrv01:

$Session=NEW-PSsession –computername DevSrv01

They were puzzled. “What did this actually do? We don’t see anything on the screen.”

Oliver explained that all this cmdlet did was open a secure session (or "phone call") to the remote server. With this session open, there are a series of cmdlets that he can enter and allow them to work remotely on the server without the need of the GUI.

He next entered in Enter-PSsession and specified the session name, called $Session, to work interactively with the remote server. In the interactive session, he entered the cmdlet to add the web URL authorization feature on DevSrv01 to demonstrate interactive remoting:

Image of command output

To exit the session, Oliver enter the following cmdlet :

EXIT-PSsession

“However, this session is still active. If we needed to, we coul send that same cmdlet from a single line in Windows PowerShell to automate that process.” Oliver entered in the Invoke-Command cmdlet to demonstrate the same work he just did interactively:

INVOKE-Command –Session $Session –scriptblock { Install-WindowsFeature Web-Url-Auth }

“Or if you want to get a bit more complex, you can have a local Windows PowerShell script run remotely. Here is a little script that might do bit more.”

INVOKE-Command –Session $Session –Filepath EnableFeatures.PS1

“But one thing we notice is the console is tied up when this runs. Is there any way to get it to run in the background?”

Oliver smiled. “Windows PowerShell has a –Job parameter to allow all of this to operate in the background of the console. Of course, we can’t leave the session active all the time. To disconnect and remove the Windows PowerShell remoting session, we run the following command:

REMOVE-PSSession –Session $session

Oliver continued. “You mentioned a problem with trying to get the Active Directory cmdlets without actually installing them?”

“Yes, this has been a major problem. We have to keep launching an RDP session to our management server to do some tasks. One of the new guys has a bad habit of using Shutdown instead of Logoff." All eyes looked to a fellow shuffling quietly in the background.

Oliver tapped his nose. “I know the answer. For this, you can use "implicit remoting," which locally creates a copy of the cmdlets on the destination server and proxies the calls to the backend system.”

Oliver created a new session to the backend management server, which had the RSAT tools installed:

$Session=NEW-PSSession –computername MgmtSrv01

He then launched a command to the remote server to import the Active Directory module into the Windows PowerShell session:

INVOKE-Command –session $Session –scriptblock { IMPORT-Module ActiveDirectory }

“We can now export cmdlets from that remote session to a brand new local module that you can save on a USB flash drive. I will export all of the Active Directory cmdlets to a module called ProxyAD.”

EXPORT-PSSession –session $Session –module ActiveDirectory –outputmodule ProxyAd

Looking at the screen, they noticed a new folder and files appear:

Image of command output

Oliver then disconnected and removed that session as previously, and he copied the folder called ProxyAD to a USB flash drive. “Walk to a new workstation and import this module to administer your Active Directory cmdlets.”

They walked to a workstation that had never had RSAT installed and ran the Import-Module cmdlet against the folder on the USB flash drive:

IMPORT-Module f:\ProxyAD

“Now,” indicated Oliver, “Try running Get-ADUser as you normally would.”

They ran the cmdlet, and the results raised their eyebrows to the ceiling. They noted how it automatically initiated the remote session and then ran the cmdlet as if it was installed locally.

Image of command output

“Oliver! You’re a genius!” They all immediately ran back to their workstations, excited to figure out all the cool and funky ways to handle their infrastructure with Windows PowerShell remoting. There was poor Oliver, left in the dust. But he was smiling a goofy smile—all because he’d made their day a little bit better by using Windows PowerShell.

Over the next few months, Oliver was really starting to enjoy his new job. Unfortunately, it was a contract position, which was ending quite soon. He was a bit nervous when a phone call came to him. It was a long-time friend of Oliver's from when he was in high school.

He presented an interesting proposition. “Oliver, I’m starting a new company. I’ve got tons of customers and I really could use your help. Would you be interested in solving some truly funky problems daily?”

Oliver paused to think. “But I almost have enough money for my flight to Redmond. I was going to try to get an interview with Microsoft. I don’t know…”

“Oliver, try this then. Give me a shot. If my company doesn’t pan, out I’ll personally write you a reference to Microsoft. What do you say?”

Oliver thought to himself. Experience would provide better ammunition if he truly wanted to work for the coolest computer company on the planet. “OK. Let’s do it!”

The next day, Oliver notified all of his friends that he found a new job at the end of his contract and thanked them for the excellent opportunity. He was excited at terrified at what the future would bring.

Will Oliver succeed or fail at his new venture? Will he ever get to fly to seek his dream job? Will anybody ever discover the secret of the Colonel’s eleven herbs and spices? Stay tuned for tomorrow’s episode of Oliver Script: A Holiday Tale on the Hey, Scripting Guys! Blog.

We invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, remember to eat your cmdlets each and every day with a taste of creativity.

Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy

Comments (1)

  1. I have eaten this one for desert 🙂 On to the next one!

Skip to main content