Convert-PodeScopedVariables,what it is for
Conversion If you have a ScriptBlock that you need to convert, in an ad-hoc manner, you can manually call Convert-PodeScopedVariables yourself. You should supply the -ScriptBlock to wish to convert, as well as an optional -PSSession SessionState from $PSCmdlet.SessionState, to this function:
convert the scriptblock's scoped variables
$ScriptBlock, $usingVars = Convert-PodeScopedVariables -ScriptBlock $ScriptBlock -PSSession $PSCmdlet.SessionState
invoke the converted scriptblock, and supply any using variable values
$result = Invoke-PodeScriptBlock -ScriptBlock $ScriptBlock -UsingVariables $usingVars -Splat -Return
Hi @Badgerati
I read document about scoped variables, and this conversion I get lost, how to use this, even if right now I do not need it yet but better understand still would be good.
Thanks Eric Xin
Hi @ericxin1982,
Any ScriptBlock supplied to Pode Routes, Middleware, Authentication, etc. will all be automatically converted - that is, any scoped variables such as $state:ExampleName will be automatically converted to something like Get-PodeState -Name 'ExampleName'
However, for any ScriptBlock you have which Pode is unaware of, and can't auto-convert, you will have to manually "convert" the ScriptBlock yourself via Convert-PodeScopedVariables - and of course, you'll only need to do this if you know the ScriptBlock will contain any scoped variables.
Convert-PodeScopedVariables will return the converted ScriptBlock, including any $using variable arguments if needed, and you can then invoke that new ScriptBlock via Invoke-PodeScriptBlock.
The -PSSession is only need if they'll be $using: scoped variables, if not it can be omitted.
Hope that helps :)
Convert-PodeScopedVariables would generate compatible scriptblock for Pode, that is what its purpose? And invoke-PodeScriptBlock is for invoking them once I need, right?
What does that mean Pode is unware of scriptblock, and need to convert, means did not define for Pode Routes, Middleware, Authentication, etc, these?
And if these scriptblock has not defined for them, and when I would use for pode, a bit strange logically.
thanks Eric Xin