Powershell – Getting started really really quick!

This is supposed to be the first introduction you get to Powershell. Start with these few steps and get further on your own.

Start a Windows Powershell Shell

Click on icon in Taskbar or, go to Start/All Programs/Accessories/Windows-PowerShell/Windows PowerShell.

Run commands

Try the following so that you will get the idea:
Use Get-Command to get a list of all available CmdLest, Functions, Aliases and Applications.
Use Get-Command *-Computer* and do a wildcard search for CmdLets where the object begins with Computer.

Run Scripts

First set the Execution Policy for the server ‘Set-ExecutionPolicy RemoteSigned‘.
Using the Tab key. Type ‘Get-Ex‘ then press Tab once. This will give you ‘Get-ExecutionPolicy‘.

Calling scripts. In order to execute a powershell scriptfile, either type the path to the file, or use tab, or drag and drop.
(Drag the file InstallMyProduct.ps1 from its location in a file explorer, drop the file in your Powershell shell window)

Write your own Scripts



[Parameter(Mandatory = $true, position = 1)]
Get-Help $Command

Paste this into a textfile, save it in C:\Scripts\ as GetHelpOn.ps1 – Execute by:
C:\sc‘ tab ‘GetH‘ Tab ‘–‘ Tab type any PS command, ex. ‘Get-ExecutionPolicy’ (Get-exe Tab)
The final command line will look like:
C:\Scripts\GetHelpOn.ps1 –Command Get-ExecutionPolicy’

What this simple script does is this: It asks for one parameter: $Command
Then it executes the Command Get-Help and adds the parameter $Command as a parameter to Get-Help, the result is the help text of the command ’Get-ExecutionPolicy’.

To add conditions to your script, use if or case:

if (condition) {code block}
elseif (condition) {code block}
else (condition) {code block}

Example (Append at the bottom of your script GetHelpOn.ps1):

if ($Command –eq “Get-ExecutionPolicy”)
{Write-host “You selected to get help on Get-ExecutionPolicy”}
elseif ($Command –eq “Get-Help”)
{Write-host “:-) You selected to get help on Get-Help!”}
else {Write-host “You selected something else…”}

More info

www.powershell.nu   http://www.powershell.se  (In Swedish)  http://technet.microsoft.com/en-us/powershell

Thats it, good luck getting started.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s