TR Dojo: Five basic PowerShell commands Windows admins should know

May 2, 2011, 8:48am PDT | Length: 00:00:00

View Transcript

Bill Detwiler shares five basic PowerShell commands Windows admins should know, such as Get-Help and Get-Service. Once you’ve watched this TR Dojo video, you can find a link to the original TechRepublic article and print the tip from our TR Dojo Blog.

2
Comments

Join the conversation!

Follow via:
RSS
Email Alert

Transcript

Bill Detwiler: PowerShell is fast becoming the managementtool of choice for Windows Admins. And if you haven’t jumped on the bandwagon,now’s the time.

I'm Bill Detwiler, and during this episode of TR Dojo, I'llgive you five basic PowerShell commands Windows admins should know.

Over the last few years, Microsoft has tried to makePowerShell the management tool of choice. As a Windows administrator, you needto be familiar with the basics of using PowerShell. So to get you started,TechRepublic blogger Brien Posey put together a list of PowerShell commandsevery Windows admin should know. I’m going to share five of those during thisepisode and I’ll link to Brien’s full list in the TR Dojo blog.

The first PowerShell cmdlet every Windows admin should learnis Get-Help.

You can use this command to get help with any other command.For example, if you want to know how the Get-Process command works, you cantype:

Get-Help -Name Get-Process

and Windows will display the full command syntax.

You can also use Get-Help with individual nouns and verbs.For example, to find out all the commands you can use with the Get verb, type:

Get-Help -Name Get-*

Although you can create and execute PowerShell scripts,Microsoft has disabled scripting by default in an effort to prevent maliciouscode from executing in a PowerShell environment. This is where the secondcommand on our list comes into play.

You can use the Set-ExecutionPolicy command to control thelevel of security surrounding PowerShell scripts.

Now there are four levels of security:

    Restricted — Restricted is the default execution policyand locks PowerShell down so that commands can be entered only interactively.PowerShell scripts are not allowed to run.

    All Signed — If the execution policy is set to AllSigned then scripts will be allowed to run, but only if they are signed by atrusted publisher.

    Remote Signed — If the execution policy is set to RemoteSigned, any PowerShell scripts that have been locally created will be allowedto run. Scripts created remotely are allowed to run only if they are signed bya trusted publisher.

    Unrestricted — As the name implies, Unrestricted removesall restrictions from the execution policy.

You can set an execution policy by entering theSet-ExecutionPolicy command followed by the name of the policy. For example, ifyou wanted to allow scripts to run in an unrestricted manner you would type:

Set-ExecutionPolicy Unrestricted

And, if you’re working on an unfamiliar server, you’llprobably need to know what execution policy is in use before you attempt to runa script or change the policy using the set-ExecutionPolicy command.

You can find out by using the third command on our list:Get-ExecutionPolicy

Fourth on our list is the Get-Service command, whichprovides a list of all of the services that are installed on the system.

If you are interested in a specific service you can appendthe -Name switch and the name of the service (wildcards are permitted) When youdo, Windows will show you the service’s state.

PowerShell can provide a wealth of information about thesystem, but sometimes you need to do more than just view the informationonscreen. Sometimes, it’s helpful to create a report that you can print orshare with a fellow admin.

Luckily the fifth command on our list, ConvertTo-HTML canhelp you do just that.

To use this command, simply pipe the output from anothercommand into the ConvertTo-HTML command. You’ll have to use the -Propertyswitch to control, which output properties are included in the HTML file andyou’ll need to provide a filename.

To see how this command might be used, consider the previouscommand I showed you—Get-Service.

When entered Get-Service creates a list of every servicethat’s installed on the system and displays in on the screen.

But wouldn’t it be a handy to have an HTML report that liststhe name of each service along with its status (regardless of whether theservice is running). To do so, you could use the following command:

Get-Service | ConvertTo-HTML -Property Name, Status >C:\services.htm

Well that does it for this episode of TR Dojo, be sure tocheck out the TR Dojo blog for links to Brien’s complete list of PowerShellcommands and more PowerShell resources..

And as always, for more teachings on YOUR path to becomingan IT Ninja, visit trdojo.techrepublic.com, sign-up for our newsletter, orfollow me on Twitter.

Thanks for visiting the TR Dojo.