![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Problems calling a function Hi, I'm having trouble calling a function from within a bunch of if statements. Basically if the user enters 50 then I want to break out and start the function "listallaccounts" which is found about 120 lines further down the script. I dont want to pass any arguments to the listallaccounts function as it contains the code to get the required input. It looks like this:- if ($servname -eq "20") {do this etc} if ($servname -eq "21") {do this etc} if ($servname -eq "50") {listallaccounts} if ($servname -eq "50") {do this etc} Function listallaccounts { cls Write-Host "This will retrieve information about user accounts on the remote server..." Write-Host $retrievefrom = Read-Host "Enter the computername that you want to scan?" $usethisaccountforthescan = Read-Host "Enter the user account on that server which authorises you to do this?" $a=get-wmiobject -ComputerName $retrievefrom -class Win32_UserAccount - credential $usethisaccountforthescan cls $a | format-list -Property name exit } However no matter what I seem to try the script just trips over the call to the function and goes onto the next line and never gets to the function I wanted. Would appreciate any help! Also has anyone got the new Lee Holmes PowerShell Cookbook yet? Is it any good? Regards, K |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Problems calling a function "Kryten" <Kryten68@xxxxxx> wrote in message news:1194450397.999710.302480@xxxxxx
know the script is processed sequentially so if it hasn't reached the definition yet then it does not exist | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: Problems calling a function Hi Kryten,
As an alternative to what Bob said you can organize your script like this conventional schema: function Main() { if ($servname -eq "20") {do this etc} if ($servname -eq "21") {do this etc} if ($servname -eq "50") {listallaccounts} if ($servname -eq "50") {do this etc} } function listallaccounts() { } .. Main This frees you from the needs to place all your helper function at the top of the script. hth Max | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) |
| Guest | Re: Problems calling a function lol What an embarassment! Thanks.....works perfectly now. $idiot=note-self ("put your functions first dopey!") Thanks again, K |
My System Specs![]() |
| | #5 (permalink) | ||||||||||||
| Guest | Re: Problems calling a function "Maximilian Hänel" <ngSpam@xxxxxx> wrote in message news:OSi8c1VIIHA.280@xxxxxx <cut>
| ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call depth reached when calling function | Victag | PowerShell | 1 | 06-03-2008 11:55 PM |
| Uninstall program function problems | SSI | Vista General | 10 | 07-15-2007 10:09 AM |
| Search function problems with VIsta | Chuck | Vista General | 4 | 05-03-2007 07:35 PM |
| calling imapi2 function put_MultisessionInterfaces return error | caijx | Vista General | 0 | 04-24-2007 11:40 PM |
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | Adam Milazzo | PowerShell | 2 | 08-11-2006 10:58 PM |