Code · 1 file
Sample PowerShell File
PowerShell is Microsoft’s object-oriented shell for Windows, macOS and Linux automation. The PowerShell sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
PowerShell · 484 B
Sample PowerShell file
An idiomatic PowerShell example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
# Sample PowerShell script — samplefiles.com
$customers = @(
[pscustomobject]@{ Id = 1; Name = 'Ada'; Balance = 12500 }
[pscustomobject]@{ Id = 2; Name = 'Grace'; Balance = 830.5 }
[pscustomobject]@{ Id = 3; Name = 'Linus'; Balance = 10000 }
)
foreach ($c in $customers) {
$vip = if ($c.Balance -ge 10000) { 'VIP' } else { '' }
'{0,-6} {1,10:N2} {2}' -f $c.Name, $c.Balance, $vip
}
'Total: {0:N2}' -f ($customers | Measure-Object -Property Balance -Sum).SumFile details
Download from the command line
curl -L -o sample.ps1 https://files.samplefiles.com/code/ps1/sample.ps1wget https://files.samplefiles.com/code/ps1/sample.ps1https://files.samplefiles.com/code/ps1/sample.ps1printf '%s %s\n' 426872aa30f85a8a9dd8e973b548c18d5fea87dd522f4e4feee47ab6ee9024b1 sample.ps1 | shasum -a 256 -cOr check the download in your browser with the checksum calculator.