If you only care about currently loaded assemblies you can use
[System.AppDomain]::CurrentDomain.GetAssemblies()
GAC Version Location
--- ------- --------
True v4.0.30319 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerSh
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_
If you care about referenced assemblies it gets complicated.
$loaded = [System.AppDomain]::CurrentDomain.GetAssemblies()
$referenced = $loaded.GetReferencedAssemblies() | select-object -Unique
That will get all loaded assemblies and all referenced assemblies. The issue is that the referenced assemblies aren't all loaded so this only gets you AssemblyName object.
$referenced
Version Name
------- ----
4.0.0.0 mscorlib
4.0.0.0 System
3.0.0.0 System.Management.Automation
4.0.0.0 System.Core
4.0.0.0 System.Xml
4.0.0.0 System.Configuration
To get the rest of the details you can use reflection.
$referenced = $loaded.GetReferencedAssemblies() | select-object -Unique | ForEach-Object {
[System.Reflection.Assembly]::ReflectionOnlyLoad($_)
}
$referenced
GAC Version Location
--- ------- --------
True v4.0.30319 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configurat
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Security\v
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.DirectoryS
Note that a lot of these are probably already loaded so you would need to get the assemblies that are loaded and remove them from the referenced list.
$referenced = $loaded.GetReferencedAssemblies() | select-object -Unique | `
ForEach-Object {
[System.Reflection.Assembly]::ReflectionOnlyLoad($_)
} | Where-Object {
$loaded.FullName -notcontains $_.FullName
}
Now the referenced list is only referenced assemblies that are not loaded.
$referenced
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_64\Microsoft.Manag
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.JSc
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Servic
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Re
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Design
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Bui
Note though that these may have referenced assemblies that are not loaded as well. So you would need to build a recursive function to iterate through them repeating the above methods if you care to dig that deep.