我有一个.net框架dll文件,它有一些类。
我想使用powershell来获取.dll文件中所有类的名称,我该怎么办?
更新:
当我尝试使用import-module "xxxxx"
时,它有以下错误。
我想你可以这样做:
$Assembly = [System.Reflection.Assembly]::LoadFrom('c:\temp\file.dll')
$Assembly.DefinedTypes
$Assembly.GetExportedTypes()
$Assembly.GetLoadedModules()
另一种方法:使用Import-Module
导入DLL并调用程序集的GetTypes()
。像这样,
PS C:\> import-module "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.SqlServer.Smo.dll"
PS C:\> $smo = ([appdomain]::CurrentDomain.GetAssemblies()) | ?{ $_.modules.name.contains("SqlServer") }
PS C:\> $smo.gettypes() | ? { $_.isPublic -and $_.isClass }