Introduction
PowerShell on macOS lets you use powerful scripts to automate tasks on your Mac, just like on Windows.
Jump into concepts and practice - no test required
powershell # Run PowerShell on macOS terminal pwsh # Example command Get-Process
pwsh Get-ChildItem -Path ~
pwsh Get-Date
pwsh
Write-Output "Hello from PowerShell on macOS!"# Save this as hello.ps1 Write-Output "Hello, macOS PowerShell user!" # Run in Terminal: pwsh ./hello.ps1
pwsh command, not powershell which is used on Windows.pwsh is the correct command to launch PowerShell on macOS.script.ps1 on macOS terminal?pwsh followed by the script name../script.ps1 tries to run the script directly, which may fail without execution permission and PowerShell context. powershell -file script.ps1 uses Windows syntax. run script.ps1 is invalid. pwsh script.ps1 correctly runs the script with PowerShell.pwsh -Command "Write-Output 'Hello macOS'"
pwsh -Command to run a PowerShell command inline, which outputs the string 'Hello macOS'.Write-Output cmdlet prints the string to the terminal, so the output will be exactly 'Hello macOS'.pwsh ./myscript.ps1 but get a permission denied error. What is the most likely fix?chmod +x myscript.ps1 adds execute permission, allowing the script to run.files.txt. Which command correctly does this?Get-ChildItem lists files and folders in PowerShell. Using ~/Documents targets the Documents folder.Out-File to save output to a file. The command runs inside pwsh -Command to execute from macOS terminal.