Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to a get a list of the currently defined functions in a powershell runspace?

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.

like image 813
briantist Avatar asked Dec 13 '25 17:12

briantist


1 Answers

Does the function PSProvider work for your needs?

Get-ChildItem function:
like image 128
Rich Rousseau Avatar answered Dec 16 '25 06:12

Rich Rousseau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!