I know that I can get the commands that were defined initially by using something like:
Runspace rs = RunspaceFactory.CreateRunspace();
rs.InitialSessionsState.Commands
or in PowerShell itself:
[System.Management.Automation.Runspaces.Runspace]::DefaultRunspace.InitialSessionState.Commands
But this only represents the state before the runspace was created.
If I import a module (even by manually creating the session state object and using sesh.ImportPSModule() before the runspace is opened), none of those functions or cmdlets will show up in the list.
Same thing if I define a new function with .AddScript() or something.
Is there any way to get the current state of the runspace rather than just the initial state, from outside the runspace?
I thought about just invoking Get-Command from inside the runspace and returning the objects, but it seems.. wrong to me for some reason. I feel like I'm missing something simple here, and there should be a way to just look at the current state and what's defined in it.
Does the function PSProvider work for your needs?
Get-ChildItem function:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With