powershell - 在哪里可以找到二进制 DSC 资源的 dll?

标签 powershell dsc powershell-module

我想扩展原始文件 DSC资源以添加support for ensuring that files not present in the source are deleted in the destination 。为此,我想至少知道原始代码是如何通过在反汇编器上检查其代码来实现的,或者尝试在 ReferenceSource 等地方找到它的实现。 ,但我怎么也找不到实现该资源的 dll 在我的计算机上的位置。

当我在 PowerShell 中发出 Get-DscResource File 命令时,Module 属性为空。然后,我尝试检查对象本身以查看是否出现任何问题,但 Path 属性也是空的,而 ParentPath 属性指向 C:\Windows\system32\Configuration\Schema\MSFT_FileDirectoryConfiguration,仅包含元数据文件,不包含二进制 dll。

我知道我可能可以使用我链接的另一个问题中描述的方法来解决这个问题,但是我们需要很多具有这种行为的文件夹,并且维护这样的脚本将是一个问题。

理想情况下,可以扩展原始类并向其中添加此行为,但我并不指望这是可能的。我只是想以原始实现作为添加此功能的基线。

考虑到这一切,我在哪里可以找到实现给定二进制 DSC 资源功能的实际 dll?

最佳答案

我做了一些挖掘,除非我错过了一些非常明显的东西,否则我认为文件资源位于“C:\Windows\System32\DscCoreConfProv.dll”中。

您已经找到了 MSFT_FileDirectoryConfiguration - 其 WMI 类位于 root\Microsoft\Windows\DesiredStateConfiguration 命名空间中:

> Get-WmiObject -Namespace "root\Microsoft\Windows\DesiredStateConfiguration" -List | `
  Where-Object { $_.Name -eq "MSFT_FileDirectoryConfiguration" } | `
  ft

   NameSpace: ROOT\Microsoft\Windows\DesiredStateConfiguration

Name                                Methods              Properties
----                                -------              ----------
MSFT_FileDirectoryConfiguration     {GetTargetResourc... {Attributes,     Checksum, Contents, CreatedDate...}

这是由 dsccoreDSC​​CoreProviders WMI 提供程序处理的:

> Get-WmiObject -Namespace "root\Microsoft\Windows\DesiredStateConfiguration" -Class "__Win32Provider" | `
  Select-Object @( "Name", "CLSID" ) | `
  ft *

Name             CLSID
----             -----
dsccore          {BADCC35D-8542-4A5C-A457-0ECCCF62508A}
DSCCoreProviders {F04C3F9B-20B3-40E1-A824-3A41FE3D7931}

假设它是 DSC​​CoreProviders 提供程序,找到 CLSID 后面的 dll:

> New-PSDrive -Name "HKCR" -PSProvider "Registry" -Root "HKEY_CLASSES_ROOT"
> (Get-ItemProperty -LiteralPath "HKCR:\CLSID\{F04C3F9B-20B3-40E1-A824-3A41FE3D7931}\InProcServer32")."(default)"

C:\Windows\system32\DscCoreConfProv.dll

但是,毕竟该文件不是 .NET Framework dll,因此您在反汇编它时可能会遇到困难。

关于powershell - 在哪里可以找到二进制 DSC 资源的 dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30263870/

相关文章:

Powershell 远程处理 : using imported module cmdlets in a remote pssession

powershell - 如何在powershell中使用 'dry-run'

Powershell 错误 : Is there a way to trap "command not found" errors into a custom function?

powershell - 使用Powershell测试应用程序链接

powershell - 如何基于脚本参数(即msbuild、gradle)在powershell中实现任务

.net - 是否安装了 .NET 版本的 DSC 资源?

PowerShell DSC - 如何将配置参数传递给 ScriptResources?

powershell - 如何解决 PowerShell V5 中的模块嵌套限制已超出错误?

azure - 使用 DSC 和 ARM 模板传递凭据并使用 Visual Studio 2017 进行部署

powershell - 无法从自定义对象中的方法调用 exit()