Script

suggest change

A script is a text file with the file extension .ps1 that contains PowerShell commands that will be executed when the script is called. Because scripts are saved files, they are easy to transfer between computers.

Scripts are often written to solve a specific problem, ex.:

Demo

MyFirstScript.ps1:

Write-Host "Hello World!"
2+2

You can run a script by entering the path to the file using an:

Usage:

> .\MyFirstScript.ps1
Hello World!
4

A script can also import modules, define it’s own functions etc.

MySecondScript.ps1:

function HelloWorld {
    Write-Host "Greetings from PowerShell!"
}

HelloWorld
Write-Host "Let's get started!"
2+2
HelloWorld

Usage:

> .\MySecondScript.ps1
Greetings from PowerShell!
Let's get started!
4
Greetings from PowerShell!

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents