gpt4 book ai didi

powershell - Powershell DSC 在哪里找到模块代码?

转载 作者:行者123 更新时间:2023-12-04 19:04:00 26 4
gpt4 key购买 nike

我在存档 DSC 模块 (MSFT_ArchiveResource.psm1) 中发现了一个错误。复制代码、在 ISE 中调试并找出需要修复的两行后,我想对真实文件进行更改并使用 Puppet 和 msutter/dsc 模块进行测试,该模块利用存档资源.

我发现我认为文件在我的机器上的位置:

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\DSCResources\MSFT_ArchiveResource\MSFT_ArchiveResource.psm1

但是,当我运行 Puppet 时,很明显我更改的代码没有被执行。 (如果我在文件顶部设置 $Debug = $true,我看不到额外的输出。)是否有一些 Windows 缓存保存了我必须清除的这个文件?它是从 ZIP 或其他存档加载的吗?

我怀疑 Puppet 是否与该问题有关,但请提及它以防它响起。 (我只在代理上更改了代码。)

更新:

当我在 Powershell 中运行以下行时,我没有找到任何预期名称包含“dsccore”的进程:
Get-WmiObject msft_providers | select -ExpandProperty provider

结果:
RegistryEventProvider
PolicyAgentInstanceProvider
CIMWin32
Msft_ProviderSubSystem
SCM Event Provider
Win32_WIN32_TERMINALSERVICE_Prov
WmiPerfClass
WmiPerfClass
WmiPerfInst
WmiPerfInst

最佳答案

Troubleshooting DSC

My resources won’t update: How to reset the cache

The DSC engine caches resources implemented as a PowerShell module for efficiency purposes. However, this can cause problems when you are authoring a resource and testing it simultaneously because DSC will load the cached version until the process is restarted. The only way to make DSC load the newer version is to explicitly kill the process hosting the DSC engine.

To identify which process is hosting the DSC engine and stop it on a per instance basis, you can list the process ID of the WmiPrvSE which is hosting the DSC engine. Then, to update the provider, stop the WmiPrvSE process using the commands below, and then run Start-DscConfiguration again.



###
### find the process that is hosting the DSC engine
###
$dscProcessID = Get-WmiObject msft_providers |
Where-Object {$_.provider -like 'dsccore'} |
Select-Object -ExpandProperty HostProcessIdentifier

###
### Stop the process
###
Get-Process -Id $dscProcessID | Stop-Process

关于powershell - Powershell DSC 在哪里找到模块代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com