View Single Post
Old 06-04-2008   #2 (permalink)
Jon


 
 

Re: Call depth reached when calling function

Try changing this line

PerfCounterValue = $perf.RawValue

to

$perf.RawValue

Yours is currently similar to a VBScript style function, where you specify
the return value in the name of the function. It works slightly differently
in Powershell - you can just write the value you want returned on a line by
its own, or you could also use a return statement

return $perf.RawValue

--
Jon


"Victag" <miketaggart@xxxxxx> wrote in message
news:5a3a79fa-2144-4712-950f-57ccc8ab20aa@xxxxxx
Quote:

> Please help...I am calling this function to try and output a perf
> counter value but I am getting call depth reached 101. I suspect I am
> recursing the fuction but not sure how else to output the value of the
> counter as the result of the function. Thanks in advance for any
> advise.
>
> Function PerfCounterValue()
> {
> #Connect to the local MSExchangeNMC Message Queued Outbound
> Performance Counter to read value
> $CounterDetail = "MSExchangeNMC","Message Queued Outbound","",
> $Computer
> $perf = New-Object
> System.Diagnostics.PerformanceCounter($CounterDetail)
> PerfCounterValue = $perf.RawValue
> #Check for errors in case counter could not be accessed
> ErrorCheck
> }
>
> $LastPerfCounterValue = PerfCounterValue
> If ($LastPerfCounterValue -eq $null)
> {Exit
> }
My System SpecsSystem Spec