Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Call depth reached when calling function

Reply
 
Old 06-03-2008   #1 (permalink)
Victag
Guest


 
 

Call depth reached when calling function

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
Old 06-04-2008   #2 (permalink)
Jon
Guest


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Calling excel function VB Script
Re: Calling function from script PowerShell
Call function with parameters that also call functions (.Net and P PowerShell
Problems calling a function PowerShell
calling imapi2 function put_MultisessionInterfaces return error Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46