Reputation: 410
$a=[AppDomain]::CurrentDomain.GetAssemblies()
$a.Count
When I run this code from powershell_ise.exe, the count is 62.
But when I run this code from powershell.exe, the count is 22.
How to get all 62 assemblies via powershell.exe?
Upvotes: 0
Views: 319
Reputation: 16116
powershell_ise.exe and powershell.exe (consolehost), VSCode (console and integrated environment ) are of course obviously different working environments, that requires and load what it needs.
$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
#>
The consoles do not require loading all the assemblies, the UX/UI stuff for example, which you have to load to use. Even the ISE does not load all of the possible assemblies on your machine. So, there are way more than either show by default. However, you can use your PowerShell profile for powershell.exe/powershell_ise.exe or VSCode profile(s)...
Microsoft.PowerShell_profile.ps1
Microsoft.PowerShellISE_profile.ps1
Microsoft.VSCode_profile.ps1
...to load whatever you choose, including all the assemblies. Just get the list of assemblies you want and use Add-Type to use them. Remember, the more you add the slower your profile will load. What you load on your profile for your dev work is fine for you, but your script should not be based/depend on your profile on distribution/production release.
In console sessions, only load what you need for your script (in your script) to execute as expected.
Note, no matter how you set up your profile(s) to do what you need. In each script, you must include all it needs to work on another system since you don't control that other user's profile.
Upvotes: 1