Hello World in PowerShell

Tutorial Difficulty Level    

This is how you would display “Hello World” in PowerShell.

Note: PowerShell commands also have the ability to be run in a script with the .ps1 extension but running scripts are disabled by default for security purposes. Firstly, you will need to set the Execution Policy. The cmdlet Get-ExecutionPolicy will show you that the initial policy is set to ‘Restricted’. This will prevent scripts from running. You can change it with the Set-ExecutionPolicy cmdlet. There are four options Restricted, Remote-signed, Signed and Unrestricted. We recommend Remote-Signed as it will allow you to run the scripts that you have created locally and still keep your machine secure.

So, just type

Now you can use notepad to create your first script. In Notepad type:

This will need to be saved in a file called something like HelloWorld.ps1.

Then from a PowerShell console type

The reason you need the .\ is because a PowerShell security feature ensures that you are targeting a specific script in a specific location,. And that’s all there is to it.