$a=[AppDomain]::CurrentDomain.GetAssemblies()
$a.Count当我从powershell_ise.exe运行这段代码时,计数是62。
但是当我从powershell.exe运行这段代码时,计数是22。
如何通过powershell.exe获得所有62个程序集?
发布于 2020-12-21 04:28:16
当然,powershell_ise.exe和powershell.exe (控制台和集成环境)、VSCode (控制台和集成环境)显然是不同的工作环境,它们需要并加载它所需要的。
$PSVersionTable.PSVersion
# Results
<#
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
#>
[appdomain]::CurrentDomain
# Results
<#
FriendlyName : DefaultDomain
Id : 1
ApplicationDescription :
BaseDirectory : C:\Windows\System32\WindowsPowerShell\v1.0\
DynamicDirectory :
RelativeSearchPath :
SetupInformation : System.AppDomainSetup
ShadowCopyFiles : False
#>
([AppDomain]::CurrentDomain.GetAssemblies()).Count
# Results
<#
37
#>
# ISE
$PSVersionTable.PSVersion
# Results
<#
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
#>
[appdomain]::CurrentDomain
# Results
<#
FriendlyName : PowerShell_ISE.exe
Id : 1
ApplicationDescription :
BaseDirectory : C:\WINDOWS\system32\WindowsPowerShell\v1.0\
DynamicDirectory :
RelativeSearchPath :
SetupInformation : System.AppDomainSetup
ShadowCopyFiles : False
#>
([AppDomain]::CurrentDomain.GetAssemblies()).Count
# Results
<#
85
#>
$PSVersionTable.PSVersion
# Results
<#
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 1 0
#>
[appdomain]::CurrentDomain
# Results
<#
FriendlyName : pwsh
Id : 1
ApplicationDescription :
BaseDirectory : C:\Program Files\PowerShell\7\
DynamicDirectory :
RelativeSearchPath :
SetupInformation : System.AppDomainSetup
ShadowCopyFiles : False
#>
([AppDomain]::CurrentDomain.GetAssemblies()).Count
# Results
<#
118
#>
# In VSCode Console
$PSVersionTable.PSVersion
# Results
<#
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
#>
[appdomain]::CurrentDomain
# Results
<#
FriendlyName : DefaultDomain
Id : 1
ApplicationDescription :
BaseDirectory : C:\Windows\System32\WindowsPowerShell\v1.0\
DynamicDirectory :
RelativeSearchPath :
SetupInformation : System.AppDomainSetup
ShadowCopyFiles : False
#>
([AppDomain]::CurrentDomain.GetAssemblies()).Count
# Results
<#
34
#>
# In VSCode Integrated (ISE-like environment)
$PSVersionTable.PSVersion
# Results
<#
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
#>
[appdomain]::CurrentDomain
# Results
<#
FriendlyName : DefaultDomain
Id : 1
ApplicationDescription :
BaseDirectory : C:\Windows\System32\WindowsPowerShell\v1.0\
DynamicDirectory :
RelativeSearchPath :
SetupInformation : System.AppDomainSetup
ShadowCopyFiles : False
#>
([AppDomain]::CurrentDomain.GetAssemblies()).Count
# Results
<#
58
#>控制台不需要加载所有程序集,例如,必须加载才能使用的UX/UI组件。甚至ISE也不会在您的计算机上加载所有可能的程序集。因此,在默认情况下,这比任何一种表现都要多得多。但是,您可以将您的PowerShell配置文件用于powershell. use /powershell_ise.exe或VSCode配置文件.
Microsoft.PowerShell_profile.ps1
Microsoft.PowerShellISE_profile.ps1
Microsoft.VSCode_profile.ps1...to加载您选择的任何内容,包括所有程序集。只需获取所需程序集的列表,并使用Add来使用它们。记住,您添加的越多,您的配置文件加载的速度就越慢。为开发工作在配置文件上加载的内容对您来说很好,但是您的脚本不应该基于/依赖于发行版/生产版的配置文件。
在控制台会话中,只加载脚本(在脚本中)按预期执行所需的内容。
注意,不管你如何设置你的个人资料来做你需要做的事情。在每个脚本中,您必须包含在另一个系统上工作所需的所有内容,因为您不控制其他用户的配置文件。
https://stackoverflow.com/questions/65384967
复制相似问题