Although, as the other answer suggests, you can change the scope of your variable to be $script:... or $global:...,
Any programmer will often say this is a bad idea. A global variable can have unexpected and really hard to troubleshoot problems and results. So instead, I'll tell you how to properly address the issue.
As you already figured out, variables inside a function don't go outside the function, but you can transport values in and out functions. Your code would become as follows:
function next() {
param
(
$counter
)
Write-host "$counter"
$counter++
return ($counter)
}
$counter = 1
$counter = next -counter $counter
$counter = next -counter $counter
$counter = next -counter $counter
$counter = next -counter $counter