Watch out! This tutorial is over 8 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
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
Set-ExecutionPolicy RemoteSigned
Now you can use notepad to create your first script. In Notepad type:
Write-Host "Hello World"
This will need to be saved in a file called something like HelloWorld.ps1.
Then from a PowerShell console type
.\HelloWorld.ps1
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.