简体   繁体   English

Powershell和模块

[英]powershell and modules

I wonder how powershell handles powershell modules - I have been reading about AppDomain, PSSession, Runspace, I wonder when powershell imports a module, is the module loaded in the same AppDomain, same runspace? 我想知道powershell如何处理powershell模块-我一直在阅读有关AppDomain,PSSession,Runspace的信息,我想知道powershell何时导入模块,该模块是否加载在相同的AppDomain,相同的运行空间中?

I know that if you put C# code in powershell, c# code will be compiled and loaded into the same AppDomain. 我知道,如果将C#代码放在Powershell中,则C#代码将被编译并加载到同一AppDomain中。 However I cannot find relevant information on Powershell module.. 但是我找不到有关Powershell模块的相关信息。

--edit-- - 编辑 -

I just run some test using 我只是使用

[System.AppDomain]::CurrentDomain.FriendlyName

It shows modules are loaded in the same AppDomain. 它显示模块已加载到同一AppDomain中。 But I still dont know about PSSession.. 但是我仍然不知道PSSession。

If you want to find out what modules are loaded execute Get-Module . 如果要找出要加载的模块,请执行Get-Module But don't confuse PowerShell modules with ProcessModule (a .dll). 但是不要将PowerShell模块与ProcessModule(.dll)混淆。 A process module could be related to PowerShell if the process module is part of a binary PowerShell module or PSSnapin. 如果进程模块是二进制PowerShell模块或PSSnapin的一部分,则该进程模块可能与PowerShell相关。 OTOH a PowerShell module can be (and often is) just a PSM1 file - no dll at all. OTOH,PowerShell模块可以只是(通常是)PSM1文件-根本没有dll。

AppDomain is very broad .NET concept that applies to all .NET processes. AppDomain是非常广泛的.NET概念,适用于所有.NET进程。 PowerShell has Runspaces which is the environment in which pipelines run your session state is managed (global variables, provider state, etc). PowerShell具有运行空间,该空间是在其中管道运行会话状态的环境(全局变量,提供程序状态等)。 Typically each PowerShell process gets a Runspace but in the case of PowerShell_ISE, it can have multiple runspaces (one per PowerShell Tab). 通常,每个PowerShell进程都有一个运行空间,但是对于PowerShell_ISE,它可以具有多个运行空间(每个PowerShell选项卡一个)。 You can see this via the following: 您可以通过以下方式查看:

PS> $ExecutionContext.Host.Runspace


Events                 : System.Management.Automation.PSLocalEventManager
ThreadOptions          : ReuseThread
JobManager             : System.Management.Automation.JobManager
RunspaceConfiguration  :
InitialSessionState    : System.Management.Automation.Runspaces.InitialSessionState
Version                : 3.0
RunspaceStateInfo      : Opened
RunspaceAvailability   : Busy
ConnectionInfo         :
OriginalConnectionInfo :
LanguageMode           : FullLanguage
ApartmentState         : STA
InstanceId             : b80ae2aa-a70b-43b2-a63f-def6c92fd032
SessionStateProxy      : System.Management.Automation.Runspaces.SessionStateProxy
Debugger               : System.Management.Automation.Debugger

Note the InstanceId will typically be the same in a PowerShell prompt. 请注意,在PowerShell提示符下,InstanceId通常是相同的。 The exceptions are jobs, event handlers and workflows which run in different runspaces (usually different processes). 例外是作业,事件处理程序和工作流,它们在不同的运行空间(通常是不同的进程)中运行。

PSSession is a somewhat different beast used to specify a pesistent remoting session to a remote computer. PSSession是用于指定到远程计算机的持久远程会话的某种不同的野兽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM