Windows Powershell is your friend!

I discovered windows powershell earlier today and have to say, this brilliant scripting tool needs to be embraced. It’s your friend!

Powershell can be downloaded from Microsoft at http://blogs.msdn.com/b/powershell/archive/2008/12/30/download-windows-powershell.aspx

For help getting started, there’s a brilliant scripting site, also available through Microsoft

http://technet.microsoft.com/en-gb/scriptcenter/powershell.aspx

You can also download a free reference card from http://refcardz.dzone.com/refcardz/windows-powershell to help you get started.

Writing a quick powershell Hello World example

1. Create the following code using notepad with the filename c:\Hello.ps1:

# Filename: Hello.ps1
Write-Host
Write-Host ‘Hello World!’
Write-Host "Good-bye World! `n"
# end of script

2. Lanch powershell (Start > Run > Powershell)

3. Type Set-Location ‘c:\’ to change the directory to where you want to run the script from

4. Type .\Hello to run the script within powershell and press enter

clip_image002

Troubleshooting

The first time I ran the script, I received an error message = Hello.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about-signing" for more details.

To fix this problem type Set-ExecutionPolicy RemoteSigned and press enter. Now re-run you script and off you go.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s