How can I reference a global variable (if it exists) or else force a local variable to be set in function?


i have function used create web service proxy:

function new-proxy  {    new-webserviceproxy -uri https://www.something.com/some.asmx -namespace test  }

when call method, want set global set such:

$global:webservice = new-proxy

next, want write functions automatically reference $global:webservice object (if exists) otherwise, want force user pass function. how set sort of test in function? pseudocode below:

function get-user  {   param(    [validatescript({     if($global:webservice)     {      $_ = $global:webservice     }     else     {      require user pass objects     }    })]    $webservice   )      # end guessing  }

sometimes simple solution elegant solution.  think you've got right, although don't use of global variables in general, in case covering yourself.


grant ward, a.k.a. bigteddy



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...