New to Powershell Scripting - was asked to look at this code to see why it fails

# Logon Errors
# 
# 
# Quick script to check logon errors since last check. Problem with the logon
# errors performance counter is it reports logon errors since last reboot, and
# the value cannot be cleared. This script is most useful with Nagios.

# Initialize values
$WarningThreshold = 5
$CriticalThreshold = 10
$z
if (Test-Path C:\logon_errors.txt) { 
	$z = Get-Counter "\Server\Errors Logon" | Select -ExpandProperty "CounterSamples"
} else {
	New-Item C:\logon_errors.txt -type file -force | Out-Null
}
[decimal]$former = get-content C:\logon_errors.txt
$current = $z.CookedValue

# Write the current logon errors reading to file
$current > C:\logon_errors.txt

# If we have readings for both the current and former logon error values, process accordingly
if ($former -And $current) {
	if ($current -lt $former) {
		# Logon errors went down. The server probably rebooted.
		Write-Host "WARNING - Logon errors counter reset. This system has probably rebooted."
		exit 1
	} elseif ($current -ge $former) {
		# Logon errors may have gone up. The real magic happens here.
		$difference = $current - $former
		if ($difference -ge $CriticalThreshold) {
			Write-Host "CRITICAL - Logon errors have exceeded the critical threshold for this check interval."
			exit 2
		} elseif ($difference -ge $WarningThreshold) {
			Write-Host "WARNING - Logon errors have exceeded the warning threshold for this check interval."
			exit 1
		} else {
			Write-Host "OK - Logon errors below warning threshold for this check interval."
			exit 0
		}
	} else {
		# Something must have gone awry if we wind up here.
		Write-Host "UNKNOWN - Could not check logon errors for this interval."
		exit 3
	}
# If not, just report normal status
} elseif ($current) {
	# Just report
	Write-Host "OK - Logon errors below warning threshold for this check interval."
	exit 0
} else {
	# Probably shouldn't arrive here, means something bad happened.
	Write-Host "UNKNOWN - Could not check logon errors for this interval."
	exit 3
}

Hello,

I am new to powershell scripting. I was asked to see why the script above fails with the default pre-defined error message of “UNKNOWN – Could not check logon errors for this interval.”.

When I try to execute the commmands one at a time (to see where it breaks), it seems that I hit an error near the start with the following command…$z = Get-Counter “\Server\Errors Logon” | Select -ExpandProperty “CounterSamples”

Any helps or suggestions would be appreciated. Thank you.