powershell 如何获取dll文件中的类等信息?

eit6fx6z  于 2023-05-22  发布在  Shell
关注(0)|答案(2)|浏览(159)

我有一个.net framework dll文件,它有一些类。
我想用powershell来获取.dll文件中所有类的名称,我该怎么做?
更新:
当我尝试使用import-module "xxxxx"时,它有以下错误。

c8ib6hqw

c8ib6hqw1#

我认为你可以做到:

$Assembly = [System.Reflection.Assembly]::LoadFrom('c:\temp\file.dll')
$Assembly.DefinedTypes
$Assembly.GetExportedTypes()
$Assembly.GetLoadedModules()
nbysray5

nbysray52#

另一种方法:使用Import-Module导入DLL并调用程序集的GetTypes()。像这样

import-module '<your_path>\Microsoft.SqlServer.Smo.dll'
$smo = ([appdomain]::CurrentDomain.GetAssemblies()) | 
    where {$_.modules.name.contains('SqlServer')}
$smo.gettypes() | where {$_.isPublic -and $_.isClass}

相关问题