I'm still not really understanding what you're doing (might be that I'm not 
reading your post the right way), but normally in code you'd have a routine 
that is somewhat like a controller: it calls all the other routines you need. 
First it would call validation routines, which would return error codes (either 
to the controller or directly to the user). Only if all the validation routines 
returned no errors would the controller routine call the routine(s) to do the 
actual work.

Is that what you're trying to build?

Cheers
Ken

From: Joseph L. Casale [mailto:[email protected]]
Sent: Monday, 17 September 2012 1:19 AM
To: NT System Admin Issues
Subject: RE: Accessing powershell variables from within a scriptblock

Hey Michael,
So this scriptblock is has variables populated by users, its then sent along as 
input to a remoting job.

I can validate with Param or other ways remotely but that requires having the 
job sent.

I guess I can remove the few that are predefined and pass them in so I can 
perform some local validation
before the scriptblock is passed and sent.

It would allow me to validate 'before' sending out the jobs, pulling them out 
would be a substantial refactor
that I was hoping to avoid.

Thanks!
jlc

________________________________
From: Michael B. Smith [[email protected]]
Sent: Sunday, September 16, 2012 8:29 AM
To: NT System Admin Issues
Subject: RE: Accessing powershell variables from within a scriptblock
Then I guess I still don't understand what you want to do. Sorry. :(

From: Joseph L. Casale 
[mailto:[email protected]]<mailto:[mailto:[email protected]]>
Sent: Sunday, September 16, 2012 8:52 AM
To: NT System Admin Issues
Subject: RE: Accessing powershell variables from within a scriptblock

Hey Michael,
That's interesting, I didn't know Param would carry forward like that. The 
issue with this is that the scriptblock is utilized
and passed to the invoke-command cmdlet regardless and is then sent on to 
remote machines which then perform the
validation.

I guess I could place an additional parameter that skipped the code execution 
and the few variables that require it, so I
could execute the block, kind of messy though.

Thanks for the insight on Param,
jlc

________________________________
From: Michael B. Smith [[email protected]]
Sent: Sunday, September 16, 2012 6:01 AM
To: NT System Admin Issues
Subject: RE: Accessing powershell variables from within a scriptblock
You can use the lambda param() block. E.g.,

[scriptblock]$MySB =
{
                Param(
                                [parameter()]
                                [Validate...()]
                                [int]
                                $count,
                                [parameter()]
                                [Validate...()]
                                [string]
                                $computername
                )
                ...
}

Replacing Validate... with the expression you need for validation and then 
build your hash from those.

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to