Repository navigation
Question about $adtSession availability in custom functions
#2084
|
Hi PSADT Team, I'm trying to understand whether it is a expected behavior that the In a test function, I was able to access However, I couldn't find any clarification on this behavior in the documentation or the "Reference" section on the website. Thanks in advance, |
Replies: 2 comments
|
The Because the above relies on happenstance, unless your extension module will always be called from a script where the script defines |
|
Hi, thanks a lot for the quick response. :) Based on your recommendation, I'll go ahead and initialize a local variable within my custom functions using Get-ADTSession. This approach also feels more aligned with the object-oriented and encapsulated design principles of the "new" PSAppDeployToolkit, rather than relying on implicit availability from a parent scope. Thanks again for the clarification! Best regards, Christian |
The
$adtSessionvariable isn't a global by any means, there's zero globals in PSAppDeployToolkit. The reason it's available in your extension module is because it's available in a parent scope of your module (i.e. it's defined in your script which is importing your extension module, therefore your script is parent to the module).Because the above relies on happenstance, unless your extension module will always be called from a script where the script defines
$adtSession, I'd recommend usingGet-ADTSessionfor consistency and reliability.