我创建了一个DSC资源来复制某个源的Modules目录.我正在测试它在我的环境中进行更广泛的部署.资源确实很好,确保所有文件都存在,并且它们与源内容相匹配,到目前为止一直很好......
问题是这样的; 我想确保如果目标或目标中有任何其他文件,则删除它们的文件夹.
这是我的代码:
Configuration TestRun
{
Param
(
$ComputerName = 'Localhost'
)
Node $ComputerName
{
File LoadModules
{
Ensure = 'Present'
Type = 'Directory'
Force = $true
Recurse = $true
SourcePath = "C:\git\Modules"
DestinationPath = 'C:\users\Jason\Documents\WindowsPowerShell\Modules'
Checksum = "SHA-256"
MatchSource = $true
}
}
}
Run Code Online (Sandbox Code Playgroud)
在第一次运行配置后,我一直在目的地目录中创建一个名为Deleteme.flag的文件进行测试.到目前为止,我还没有运气实际被删除.
我尝试添加一个额外的文件提供程序要求,以在运行之前删除该目录:
File RemoveModules
{
Ensure = 'absent'
Type = 'Directory'
Force = $true
Recurse = $true
DestinationPath = 'C:\users\Jason\Documents\WindowsPowerShell\Modules'
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这失败并出现以下错误:
关键属性组合'C:\ users\Jason\Documents\WindowsPowerShell\Modules'与节点'Localhost'中资源'File'的键'DestinationPath'重复.请确保关键属性对于节点中的每个资源都是唯一的.
无论如何,我想用文件资源来做,但显然,使用脚本提供程序或其他一些自定义资源很容易做到这一点.在此先感谢您的帮助!
我有一个简单的PowerShell DSC配置块,可确保用户帐户不存在,当我尝试将其应用到本地系统时Start-DscConfiguration,我收到类似于以下内容的错误消息:
WS-Management服务无法处理请求.WMI服务返回"拒绝访问"错误.
如何成功应用DSC配置?
这是我正在使用的配置块:
configuration MyConfig {
User Trevor2 {
UserName = 'Trevor2';
Ensure = 'Absent';
}
}
$Path = 'c:\dsc\MyConfig';
MyConfig -OutputPath $Path;
Start-DscConfiguration -Wait -Verbose -Path $Path;
# Clean up MOF files
Remove-Item -Path $Path -Recurse;
Run Code Online (Sandbox Code Playgroud) 我的MSMQ队列由PowerShell DSC引擎创建.我可以看到队列被创建了.由于DSC引擎从SYSTEM帐户运行,因此队列所有者也设置为SYSTEM.当我尝试从PowerShell控制台设置MSMQ ACL时,我不断收到以下错误:
PS C:\Users\Administrator.DOMAIN> whoami; Get-MsmqQueue queue1 | Set-MsmqQueueACL -UserName "Everyone" -Allow FullControl
DOMAIN\administrator
Set-MsmqQueueACL : Failed to set security descriptor. Error code: 3222143013
At line:1 char:50
+ whoami; Get-MsmqQueue incredipay_atm_processor | Set-MsmqQueueACL -UserName "Eve ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (FullControl:MessageQueueAccessRights) [Set-MsmqQueueACL], Win32Exception
+ FullyQualifiedErrorId : Failed to set security descriptor. Error code: 3222143013,Microsoft.Msmq.PowerShell.Commands.SetMSMQQueueACLCommand
Run Code Online (Sandbox Code Playgroud)
我也无法使用自定义DSC资源设置MSMQ ACL,这基本上只从SYSTEM帐户执行相同的操作.所以问题是有没有办法使用Set-MSMQQueueACL cmdlet在PowerShell DSC引擎中设置MSMQ权限.或者至少如果我能够解决前面提到的错误,那么也许我也能解决DSC问题.我正在运行Windows 2012和WMF 4.0.
提前致谢.
我注意到如果通过Start-DscConfiguration失败应用配置,它会写入错误流但不会抛出异常?也就是说,如果我执行以下操作:
try{
Start-DscConfiguration -Path ".\MyConfig" -Wait -Verbose
}catch{
#...
}
Run Code Online (Sandbox Code Playgroud)
......它永远不会在catch处理程序中结束.我怀疑这可能与以下事实有关:没有"-Wait",
Start-DscConfiguration为此启动异步作业,异步命令可能不会抛出异常,但在同步场景中,我非常想知道我的配置是否可以应用.
确定是否Start-DscConfiguration已成功完成的正确方法是什么?
我在Archive DSC模块中发现了一个错误(MSFT_ArchiveResource.psm1).在复制代码,在ISE中调试代码并找出需要修复的两行之后,我想对真实文件进行更改并使用Puppet和msutter/dsc模块进行测试,该模块使用归档资源.
我发现我认为文件在我的机器上的位置:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\DSCResources\MSFT_ArchiveResource\MSFT_ArchiveResource.psm1
Run Code Online (Sandbox Code Playgroud)
但是,当我运行Puppet时,很明显我的更改后的代码没有被执行.(如果我在文件的顶部设置$ Debug = $ true,我没有看到额外的输出.)是否有一些Windows缓存保存此文件,我必须清除?是从ZIP还是其他档案加载?
我怀疑Puppet是否与这个问题有关,但是如果它敲响了铃,就提起它.(我只在代理上进行了代码更改.)
更新:
当我在Powershell中运行以下行时,我找不到任何包含"dsccore"的预期名称的进程:
Get-WmiObject msft_providers | select -ExpandProperty provider
Run Code Online (Sandbox Code Playgroud)
结果:
RegistryEventProvider
PolicyAgentInstanceProvider
CIMWin32
Msft_ProviderSubSystem
SCM Event Provider
Win32_WIN32_TERMINALSERVICE_Prov
WmiPerfClass
WmiPerfClass
WmiPerfInst
WmiPerfInst
Run Code Online (Sandbox Code Playgroud) 我正致力于在Azure VM上自动部署我们的产品.我正在使用Powershell DSC和Azure自动化来配置VM.
其中一个要求是为VM上的用户导入pfx证书到CurrentUser/My.我试图使用以下脚本资源执行此操作:
Script InstallSelfSignedCertificatesToMy
{
GetScript = {
}
SetScript = {
$Path = "c:\test"
$Pass = ConvertTo-SecureString "password"-AsPlainText -Force
Import-PfxCertificate -FilePath "$($Path)\example.pfx" cert:\currentUser\my -Password $Pass
}
TestScript = {
return $false
}
Credential = $adminCredential
}
Run Code Online (Sandbox Code Playgroud)
$ adminCredential参数具有我要导入证书的用户的凭据.
此DSC不报告任何故障,但证书未添加到用户的CurrentUser/My上.
一个有趣的观察是,如果我使用Start-DscConfiguration在VM上本地运行DSC,它将按预期工作并安装证书.如果从Azure自动化调用它,它不起作用.
任何人都可以指出这里可能存在的问题吗?有没有人试图做类似的事情?
提前致谢.
我无法使用资源管理器模板以编程方式查找有关向WebApps添加插槽的信息/指南.我的基本配置运行良好,创建了WebApp本身,SQL服务器,SQL DB等,但我也很想完成插槽,所以我可以将它们用于开发/测试版本.
有谁知道这有什么好资源?
我正在探索DSC并想知道将DSC资源复制到目标主机的最佳方法是什么?
当我尝试将配置推送到目标主机时,它抱怨缺少DSC资源.
The PowerShell DSC resource xWebAdministration does not exist at the PowerShell module path nor is it registered as a WMI DSC resource.
+ CategoryInfo : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : DscResourceNotFound
+ PSComputerName : server1.appman.net
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过DSC配置目标节点.
我创建了一个带有虚拟配置的.ps1文件; 你可以在下面看到它; 它只是您在DSC站点中找到的第一个示例之一.
现在我想将它编译成.mof文件.我执行了:
PS C:\var\DSC\Configurations> . .\localhost.ps1
Run Code Online (Sandbox Code Playgroud)
但它什么都没做.mof文件不会出现,也不会抛出任何错误消息.我错过了什么?
Configuration FileResourceDemo
{
Node "localhost"
{
File DirectoryCopy
{
Ensure = "Present" # You can also set Ensure to "Absent"
Type = "Directory" # Default is "File".
Recurse = $true # Ensure presence of subdirectories, too
SourcePath = "C:\Users\Public\Documents\DSCDemo\DemoSource"
DestinationPath = "C:\Users\Public\Documents\DSCDemo\DemoDestination"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID DirectoryCopy"
DependsOn = …Run Code Online (Sandbox Code Playgroud) 鉴于这个简单的配置文件:
Configuration MyDscConfiguration {
Node "TEST-PC1" {
WindowsFeature MyFeatureInstance {
Ensure = "Present"
Name = "RSAT"
}
WindowsFeature My2ndFeatureInstance {
Ensure = "Present"
Name = "Bitlocker"
}
}
}
MyDscConfiguration
Run Code Online (Sandbox Code Playgroud)
运行时,为节点"TEST-PC1"生成的MOF文件将放在名为的子目录中MyDscConfiguration.
我正在寻找一种方法将MOF输出到自定义目录位置,例如 mofs\MyDscConfiguration\
这可能吗?