PowerShell

Hello World!

Leerdoelen

  • Een eerste script leren maken
  • Testen of alles werkt

Test script

  • Start PowerShell
  • cd $home
  • New-Item -Path Directory -Path PowerShell
  • Open notepad.exe
  • Neem deze code over:
    write-host "Hello world!"
  • Sla op als hello_world.ps1 in de nieuwe PowerShell directory
  • LET OP: notepad gebruikt standaard .txt extensie

De code

write-host "Hello world!"
  • Hello World! staat tussen quotes en is een string
  • write-host is een cmd-let en print data op het scherm
  • Deze opdracht schrijft dus Hello World! op het scherm

Start script

  • Start PowerShell
  • cd $home
  • cd PowerShell
  • dir
  •     Directory: C:\Users\dleeu\PowerShell
    
    Mode       LastWriteTime  Length Name
    ----       -------------  ------ ----
    -a---- 3/31/2026 8:54 AM      25 hello_world.ps1
  • PS C:\Users\dleeu\PowerShell> .\hello_world.ps1
    Hello World!

Of een error...

  • File .\hello_world.ps1 cannot be loaded because running scripts \
    		is disabled on this system.
  • De oplossing:
    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
  • Test .\hello_world.ps1 opnieuw!

Samenvatting

  • We hebben een eerste script gemaakt
  • We hebben met write-host data naar het scherm geschreven
  • We hebben een script opgestart