Posted by: Richard Siddaway
I had a comment left on one of my posts recently that mentioned a “Hello World” script. The concept of a Hello World program/script is that it is a simple introduction to using a new language that gives a known result.
For a brand new user to PowerShell is is how you create a Hello World script:
open PowerShell with elevated privileges (Run as Administrator)
type Set-ExecutionPolicy RemoteSigned –Force and press enter
This enables scripts to run.
Run these two lines by typing them individually and pressing enter
New-Item -Path c:\ -Name TestScripts -ItemType Directory cd C:\TestScripts
They create a test folder and move your location to that folder
“‘Hello World’” > script1.ps1
and press enter. This creates your script. The single quotes nested in the double quotes are so that the text in the script will be surrounded by quotes – its a string value.
Run the script by typing
and pressing enter. You will see the results:
The .\ is required as PowerShell won’t run commands in the current folder by default. You have to explicitly give the local path.
You’ve now written your first PowerShell script and discovered most of the “gotchas” that cause people problems when they are first learning PowerShell