我知道我可以通过使用以下脚本块来确保特定注册表值的存在:
Registry ConfigureRegistry
{
Ensure = 'Present'
Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\SomeKey'
ValueName = 'MachineType'
ValueData = 'Hyper-V'
}
Run Code Online (Sandbox Code Playgroud)
但是如何删除注册表项SomeKey?如果我只将关键字更改Ensure = "Present"为Ensure = "Absent"它会留下密钥SomeKey......
我的 DSC 配置中有以下内容:
xWebApplication StaffDirectoryApp {
Website = "MySite"
Name = "MyApp"
WebAppPool = "MyPool"
PhysicalPath = $Destination
Ensure = "Present"
PreloadEnabled = $true
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,但我还想使用 AuthenticationInfo 属性(尽管文档似乎说它应该是 AuthenticationInformation,但事实并非如此)。
我能找到的唯一例子是 GitHub 上的一个单元测试,它们的用法是这样的:
AuthenticationInfo = New-CimInstance -ClassName MSFT_xWebApplicationAuthenticationInformation `
-ClientOnly `
-Property @{ Anonymous = $false; Basic = $false; Digest = $false; Windows = $true }
Run Code Online (Sandbox Code Playgroud)
然而,这会产生以下结果:
Convert property 'AuthenticationInfo' value from type 'STRING' to type 'INSTANCE' failed
Run Code Online (Sandbox Code Playgroud)
我应该如何设置这个属性?
我有一个 Powershell DSC 自定义资源,嵌入在模块中。如果您想查看完整的代码,可以在这里找到,但这可能不是必需的;我的问题不在于(我认为)我编写的代码,而在于如何访问它。
就我而言,我使用的是 DSC 推送模式。我使用一个普通的 Powershell 脚本来安装所需的模块、编译配置并启动它。在该脚本中,我将模块的位置添加到$env:PSModulePath. 完成此操作后,我可以看到该模块并将其导入我的交互式 shell 中,如下所示:
PS> Get-Module -ListAvailable | Where-Object -Property Name -eq cWinTrialLab | Import-Module
PS> Get-DscResource -Module cWinTrialLab
ImplementedAs Name ModuleName Version Properties
------------- ---- ---------- ------- ----------
PowerShell cWtlShortcut cWinTrialLab 0.0.1 {Ensure, ShortcutPath, TargetPath, DependsOn...}
Run Code Online (Sandbox Code Playgroud)
所以我创建一个测试配置文件:
Configuration TestConfig {
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName cWinTrialLab
Node localhost {
cWtlShortcut "TestShortcut" {
Ensure = "Present"
ShortcutPath = "$env:USERPROFILE\Desktop\TestShortcut.lnk"
TargetPath = "C:\Windows\system32\cmd.exe"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用它:
PS> . …Run Code Online (Sandbox Code Playgroud) 我正在遵循MSDN 上最基本的示例,但未能使其正常工作。我的配置定义如下:
Configuration MyWebConfig
{
Param($ComputerName)
Node $ComputerName {
WindowsFeature MyRoleExample
{
Ensure = "Present"
Name = "Web-Server"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用C:\Scripts> .\IisWithCompressionConfig.ps1 -ComputerName "localhost" -Outputpath C:\Scripts\localhost(以及其他几个命令行变体)生成 MOF 。我没有得到任何文件输出,也没有报告错误(退出状态代码也是 0)。我试过一个没有$ComputerName变量的版本(而是“本地主机”硬编码),仍然没有。是的,我在提升的提示下运行它。
我已经确定我正在运行 PowerShell 4.0:
C:\Scripts> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34003
BuildVersion 6.3.9600.16394
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
Run Code Online (Sandbox Code Playgroud)
任何想法我错过了什么?
我正在尝试应用使用来自已安装模块的资源的 DSC 配置。但是,当我运行时Start-DscConfiguration,出现此错误:
PowerShell DSC 资源 ******** 不存在于 PowerShell 模块路径中,也未注册为 WMI DSC 资源。
+ CategoryInfo : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
+fullyQualifiedErrorId : DscResourceNotFound
但是,当我登录服务器并运行时Get-DscResource,缺少的资源就在那里。
为什么DSC找不到资源?
以下命令可用于确定系统上是否存在配置漂移:
Test-DscConfiguration –CimSession $session
Run Code Online (Sandbox Code Playgroud)
该命令仅返回 true 或 false。有没有办法检索这些差异的列表?
原本应该是简单的注册表 DSC 配置已经变成了令人有些沮丧的猜测。我正在尝试设置二进制注册表项。我发现不可能找到正确的值数据格式来正确设置密钥。我正在尝试将此注册表文件转换为 DSC:
\n\n[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\DefaultSecurity]\n"SrvsvcShareAdminConnect"=hex:01,00,04,80,64,00,00,00,70,00,00,00,00,00,00,00,\\\n 14,00,00,00,02,00,50,00,03,00,00,00,00,00,18,00,03,00,0f,00,01,02,00,00,00,\\\n 00,00,05,20,00,00,00,20,02,00,00,00,00,18,00,03,00,0f,00,01,02,00,00,00,00,\\\n 00,05,20,00,00,00,25,02,00,00,00,00,18,00,03,00,0f,00,01,02,00,00,00,00,00,\\\n 05,20,00,00,00,27,02,00,00,01,01,00,00,00,00,00,05,12,00,00,00,01,01,00,00,\\\n 00,00,00,05,12,00,00,00\nRun Code Online (Sandbox Code Playgroud)\n\n我已经对注册表和 xregistry 资源进行了尝试,并遇到了相同的格式错误(我真的不介意我使用哪个)。我尝试将数据提供为单个字符串、字符串数组、附加 0x 以显示它是十六进制的字符串数组等。我也尝试了这里的建议。
\n\n我得到的最接近的是下面的配置,它似乎有效:
\n\n Registry disableAdminShare {\n Ensure = "Present"\n Key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\DefaultSecurity"\n Force = $true\n ValueName = "SrvsvcShareAdminConnect"\n ValueData = @("010004806400000070000000000000001400000002005000030000000000180003000f00010200000000000520000000200200000000180003000f00010200000000000520000000250200000000180003000f0001020000000000052000000027020000010100000000000512000000010100000000000512000000")\n ValueType = "Binary"\n }\nRun Code Online (Sandbox Code Playgroud)\n\n但查看应用时的日志,它似乎将值转换为十进制,导致无效条目:
\n\n\'HKLM:\\SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\DefaultSecurity\\SrvsvcSha\nreAdminConnect\' to \'(1, 0, 4, 128, 100, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 20,\n0, 0, 0, 2, 0, 80, 0, 3, 0, 0, 0, 0, 0, 24, 0, 3, …Run Code Online (Sandbox Code Playgroud)