Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Global or Passed vars?

$
0
0

I have a situation where I am going to process a series of "Packages" which contain an arbitrary series of "Tasks" and I need to then write that info to the registry in a "Package" Key and "Task" Values. The actual Package and Task processing happens with For Each loops.

I can see two ways of doing this.

1: A global variable $CurrentPackage, and the end of Process-Task writes to .../$CurrentPackage/$Task

2: No global variable, $Package is passed as a string to Process-Task along with $Task.

I have some other similar situations, so I am curious if there are any general best practices on use of Global vars vs passing more info to Functions. Also, when using global variables, is it best practice to name them so that scope is obvious? In VBScript I used G_strName or the like to make scope obvious. But PowerShell seems to dispense with most nomenclature beyond overall use of the variable. 

Thanks!
Gordon


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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