首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell大会

PowerShell大会
EN

Stack Overflow用户
提问于 2020-12-20 21:27:25
回答 1查看 121关注 0票数 0
代码语言:javascript
复制
$a=[AppDomain]::CurrentDomain.GetAssemblies() 
$a.Count

当我从powershell_ise.exe运行这段代码时,计数是62。

但是当我从powershell.exe运行这段代码时,计数是22。

如何通过powershell.exe获得所有62个程序集?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-21 04:28:16

当然,powershell_ise.exe和powershell.exe (控制台和集成环境)、VSCode (控制台和集成环境)显然是不同的工作环境,它们需要并加载它所需要的。

代码语言:javascript
复制
$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配置文件.

代码语言:javascript
复制
Microsoft.PowerShell_profile.ps1
Microsoft.PowerShellISE_profile.ps1
Microsoft.VSCode_profile.ps1

...to加载您选择的任何内容,包括所有程序集。只需获取所需程序集的列表,并使用Add来使用它们。记住,您添加的越多,您的配置文件加载的速度就越慢。为开发工作在配置文件上加载的内容对您来说很好,但是您的脚本不应该基于/依赖于发行版/生产版的配置文件。

在控制台会话中,只加载脚本(在脚本中)按预期执行所需的内容。

注意,不管你如何设置你的个人资料来做你需要做的事情。在每个脚本中,您必须包含在另一个系统上工作所需的所有内容,因为您不控制其他用户的配置文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65384967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档