Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Function not recognized out of PowerISE in the same script

$
0
0

Hi everyone,

I did a powershell script which launch a window with some functionalities and during all of the development in PowerISE I didn't care about the scope of the variables. So I learned about this important thing and fixed variables scope issues. But it seems that there is a problem I'm still unable to resolv without using "global" parameter but I'd like to avoid it.

My problem is that I made a function into the script, and when I call it from another function it doesn't work.

Here you are a part of my script:

#Functions
function RefreshDetail
{
    try
    {
        Invoke-ArrayRetrieve -adEnableUserList $adEnableUserList  -> One of my module
        Invoke-ComboFillByArray -arrayEnableList $arrayEnableList -> One of my module
    }
    catch [System.Net.WebException],[System.Exception]
    {
        Show-MessageBox -Message $_.Exception.Message -Icon Stop
    }
}

#Main

New-Window -WindowStartupLocation CenterScreen -Width 500 -Height 500 -Content {

   New-StackPanel -ControlName 'user' -Children {

      New-Grid -Rows 3 -Columns 2 -Children {

          New-StackPanel -Name 'top_left' -Row 0 -Column 0 -Children {

              New-Button -Name disable -Content 'Disable' -Height 25 -On_Click {
                  try
                  {
                      if(!$arrayEnableList) #If the array is empty
                     {
                         throw 'There is no enabled user !'
                     }
                     else
                     {
                           if($comboEnableUser.SelectedIndex -gt -1) #If a combobox item is selected
                          {
                               DisableAccount -> FAIL
                           }
                           else
                           {
                               throw 'You try to make operations on an invalid user !'
                           }
                    }
                }
               catch [System.Net.WebException],[System.Exception]
               {
                    Show-MessageBox -Message $_.Exception.Message -Icon Stop
               }
          }

...

The error I got is :

http://s12.postimg.org/xw8xtztul/2015_02_06_17_15_08.png

Have you got any idea ?

Thanks in advance,

Arnaud






Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>