Learn about Windows PowerShell
Microsoft Scripting Guy Ed Wilson here. It’s Sunday and there are only eight more days until the 2010 Scripting Games commence. Craig and I have nearly completed all of our preparations, but it seems there are always last minute things going. I have to do a Live Meeting with a .NET user group in Tulsa on Wednesday. I will spend a couple hours on Tuesday getting ready for that presentation. I have a few conference calls, and other than that I will be writing scripts, articles, and hanging out on Twitter and Facebook. I will spend some time each day going over the e-mail sent to firstname.lastname@example.org and that is about it.
I enjoy sitting around the table, sipping a nice cup of English Breakfast Tea and thinking about my week to come. It is quiet in the early morning.
No computer hums,
PowerSaver mode is enabled,
It doesn’t know the words?
I close my eyes and try to think about the progress that the Scripting Wife is making learning Windows PowerShell. I wrote the events for the 2010 Scripting Games several months ago, and I do not readily remember the content of each of the events. She has been using the 2010 Scripting Games Study Guide to get ready for the competition; but there is still a narrow road to navigate before reaching the starting line for the events.
In syllables, he’s
Trying to think and to count,
The words don’t add up.
“I have been thinking, there are eight days before you expect me to write a script for the 2010 Scripting Games, and I cannot even get a script to run. Something doesn’t make sense here,” the Scripting Wife said as she entered.
“Good morning to you my dear. What happened to my bride who used to hibernate on the weekends?” I cooed.
“Is that a nice way of saying I am disturbing your peace?” she accused.
“Let it not be so,” I stammered. “I am thrilled, overjoyed, and enthralled,” I said.
“Then are you going to show me how to get a script running, my little script monkey?” she joked.
“Stop that. It’s not funny. Besides, I believe there is a law about jocularity before 6:00 A.M. But let’s get to it,” I said with as much enthusiasm as I could muster.
“Are you going to make me the administrator?” she asked engagingly.
“Don’t hold your breath,” I said under my breath.
“What was that, my little script monkey?” she queried.
“I said that granting you administrator rights will not be necessary,” I mumbled.
“So how am I going to make my script run?” she asked.
“Right-click your shortcut to Windows PowerShell that you saved on your desktop the other day,” I said.
“Like this,” she said turning her laptop to where I could see the monitor. She showed me what’s shown in the following image.
“That is right. Now click Run as…”
“Okay. Now what do I type?” she asked.
“Here, let me see your laptop for a second,” I said, as I quickly typed in the administrator credentials for the domain.
“Here, let me see your laptop for a second,” I asked. “When the Windows PowerShell console appears, it will be running as if the domain administrator were logged on to the computer.”
“Now that we are running the Windows PowerShell console with administrator rights—you can see that in the title bar—type Get-ExecutionPolicy to see the current script execution policy setting,” I said.
“Do I have to be a domain administrator to see the script execution policy? That is dumb. What if I need to know if I am permitted to run scripts? Am I supposed to call you up and ask?” she asked appropriately.
“You can run the Get-ExecutionPolicy cmdlet anytime you wish. Because we already know we need to change the script execution policy, we logged in as the administrator. The Get-ExecutionPolicy cmdlet tells us that the policy is set to Restricted, which means that no scripts are allowed to run,” I said.
“We already knew that. Quit messing around and fix it,” she said with just a hint of exasperation in her tone.
“To set the script execution policy, use the Set-ExecutionPolicy cmdlet and give it the name of one of the allowed policy settings. For now, because I know you will not be downloading any scripts from the Internet, set the policy setting to Unrestricted. This will permit you to run any script you have,” I said. “When you see the warning message, type Y for yes.”
“Ok. It is done!” she said triumphantly. She showed me what you see in the following image.
“How can I test it?” she asked.
“Go to your Windows PowerShell ISE, and try to run that test1 script you wrote yesterday,” I suggested.
“It was already open. Do I need to log out and log back in, or reboot for this to work?” she asked.
“Go ahead and try it,” I said playfully. “All it can do is give you the same error you have been seeing for the last day or so. That does not hurt anything.”
“Nothing but my pride. It feels like it is yelling at me when it shows all those errors. It seems hostile,” she continued. “Maybe I better reboot just to be on the safe side.”
“Don’t do that. Your laptop is a bit slow rebooting.”
“My laptop is quite a bit slow all the time,” she complained. “Okay, I will run the script, but if it yells at me…oh, cool, it works.”
“You mentioned the registry yesterday. Go ahead and open regedit,” I said.
“I was kidding.”
“I am not,” I said.
“Ok, but do I need to do that Run as trick again?”
“No. You have to have rights to read the registry, or else Windows PowerShell would not know whether or not to run the script. It is stored in the registry,” I said.
“That is pretty cool,” the Scripting Wife admitted. “I am going to go write some scripts and let you go back to doing whatever you were doing.”
“Okay…hmmm…the registry…I wonder…if it will work?”
Keys are there for me to see,
Have I permission?
If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at email@example.com or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys