Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Named parameters with Scope

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-03-2008   #1 (permalink)
Martin Zugec
Guest


 

Named parameters with Scope

Heya,

I love named parameters (I even used them in batches), so I really want all
my scripts to support them. However I run into problem when I try to define
also scope:

Param (
[string]$Global:JobStorage = $(throw "You must specify folder where you
jobs are stored as parameter."), #Get folder where jobs are stored
[string]$GlobalebugLog = $("$pwd\S4M_EngineDebug.log") #Location of debug
log (log file from current session. Optional parameter
)

If scope ($Global is specified, -JobStorage "C:\Temp" won't work...

Not sure whether it is bug or feature - I can imagine it was implemented to
prevent situation like
Param (
[string]$Global:JobStorage = $(throw "You must specify folder where you
jobs are stored as parameter."), #Get folder where jobs are stored
[string]$Private:JobStorage = $(throw "You must specify folder where you
jobs are stored as parameter."), #Get folder where jobs are stored
)

Martin


My System SpecsSystem Spec
Old 07-03-2008   #2 (permalink)
sapienscripter's Avatar
Scripting Guru


Join Date: Jun 2008
Vista Ultimate 32bit
Syracuse, NY
 
Rep Power: 8
sapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura about
  sapienscripter is offline

Re: Named parameters with Scope

Why are you scoping your variables? This is a dangerous practice unless you know exactly what you are changing and why. The best practice is that functions should never modify the global scope.
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this a bug in the scope? Joel (Jaykul) Bennett PowerShell 1 08-18-2008 11:33 AM
Variable scope Altraf PowerShell 6 12-13-2007 10:41 AM
trap scope Bob Butler PowerShell 9 10-27-2007 08:41 PM
Powershell and scope wkempf PowerShell 12 04-02-2007 04:13 PM
using named parameters in a SetScriptBlock (typedata) /\\/\\o\\/\\/ PowerShell 1 07-17-2006 08:14 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008