You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
Because I use "invoke-command" cmdlet in block of Requirements and I would like to use a PSSession instead of creating a new session each time I invoke a remote command. Initiate a New-PSSession inside a Requirement is mandatory because in my code I test the WinRM connection before invoking any remote command, like:
No, in your example $PSSession is declared in a script block, so it is only scoped to that scriptblock, whereas in my example, $sharedState is defined outside any script block--that's why you have to set properties on the referenced object instead of only setting the variable.
I haven't used this module recently so I'm a little rusty, but you might also need to call the GetNewClosure() method on the scriptblock itself.
Hello @chriskuech ,
Could we passthrough variables between block ?
Because I use "invoke-command" cmdlet in block of Requirements and I would like to use a PSSession instead of creating a new session each time I invoke a remote command. Initiate a New-PSSession inside a Requirement is mandatory because in my code I test the WinRM connection before invoking any remote command, like:
@{ Describe = "Test WinRM connection '$VmName'" Test = { $online = $false ; while ($online -ne $true) { try { Test-WSMan -ComputerName $VmName -ErrorAction Stop ; $online = $true } catch { Start-Sleep 5 } } } },
Thank you !
The text was updated successfully, but these errors were encountered: