PowerShell Hello World Script

by percent20 1/15/2008 6:01:00 AM

I have been wanting to learn PowerShell for a while now and one of the guys in the #alt.net irc channel talks about it all the time. So I decided to give it another shot.  The first thing I wanted to do was write a Hello World script that just out put that text to the screen running form a script file.  It wasn't so easy to figure it out believe it or not and there wasn't a good Hello World tutorial on the net I could find.  Finally, after a while of just trying stuff and following half instructions I figured out how to get a script to run.

First though you need to Download PowerShell. Please follow that how-to on downloading PowerShell.

After powershell is installed open up the powershell command window and notepad.  I'm not going to go into the why of powershell here because honestly I don't know yet.  Instead i'll give you quick instructions for writing a script that will run.

  • In notepad type out the following ( Write-Output "Hello World" ) without the parenthasis
  • Save file as HelloWorld.ps1
  • Switch to PowerShell command window
  • Navigate to the folder you saved the file in ( I just used C:\ to keep it easy at first )
  • Execute the following command: Set-ExecutionPolicy RemoteSigned (reduces security until you increase it.  There is a very annoying security policy in place for just dev work)
  • Next is to run the script just d: ./HelloWorld.ps1
It should have spit out Hello World do the console.  Congrats you just did a hello world script in powershell 

HelloWorld.ps1 (26.00 bytes)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

powershell

Related posts

Comments

1/15/2008 8:46:14 AM

halr9000

Honestly, it's even easier than that. Remember, PowerShell is a shell, not just a scripting host like vbscript. You could just type the above command right at the command-line and you'll get the same effect without creating an actual script file.

Also note that just typing "Hello World" by itself will do the same, so you could get even shorter. Smile

halr9000 us

1/15/2008 12:28:59 PM

percent20

I agree that is a really cool thing about powershell and I saw that all over the place. My biggest thing is I wanted to do something basic in a shell script file .ps1 just a simple hello world in it. So that was the goal behind this hello world since I wasn't able to find one similar.

Thanks for leaving a comment and mentioning that. It is good to know and I didn't want to go into details like that with this post. In the future I might Smile

Thanks again,
Buddy

percent20 us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/25/2008 12:14:33 AM

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen


My Flare

AddThis Feed Button

National Blog Posting Month

Eagle Scout

I'm Test Driven

[Reserved for MVP status I want to earn]

View Buddy Lindsey's profile on LinkedIn

Twitter



Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in