# Echo command-line input
$args -join " "
(Yes, it's a single line.)# Count duplicates in a file
$lines = @{}
foreach ($path in $args) {
cat $path | % { $lines[$_] += 1 }
}
$lines.GetEnumerator() | % { if ($_.Value -gt 1) { "$($_.Value)`t$($_.Name)" } }
# GET request param($url)
irm $url
# Parallel GET requests $before = get-date
$args | % -parallel {
$res = iwr $_
$after = get-date
$time = ($after - $using:before).TotalSeconds
"${time}s`t$($res.RawContentLength)`t$_"
} -ThrottleLimit 12345
$after = get-date
$time = ($after - $before).TotalSeconds
"${time}s elapsed"
I'm showcasing a few different ways of doing things: using $args, using the param directive; using foreach, or % which is an alias of ForEach-Object; irm for Invoke-RestMethod, iwr for Invoke-WebRequest...