【发布时间】:2018-06-16 13:55:04
【问题描述】:
我已经在 PowerShell DSC 中开始了小步骤。
到目前为止,我已经创建了几个 DSC 脚本并且都按预期工作。
我尝试删除特定路径中的子目录。但是文件资源正在删除所有子文件夹和父文件夹。
我希望根文件夹处于活动状态并删除子目录。
请为此任务提供建议。
这是我的代码
#requires -version 4.0
#requires -RunasAdministrator
param(
[parameter(Position=0,Mandatory)]
[string[]]$Computers
)
Configuration RemoveWorkspace{
param(
[parameter(Position=0,Mandatory)]
[string[]]$Computers
)
Node $computers {
File RemoveDiretory{
Type = "Directory"
DestinationPath = "E:\Builds\1946"
Force = $true
Ensure = "Absent"
Recurse = $true
}# end File
}# end node
}#end configuration
#create config data to allow plain text passwords
$configData=@{AllNodes=$null}
#initialize an array for node information
$nodes=@()
ForEach($computer in $Computers){
write-host " Adding $computer "-ForegroundColor Green
#define a hashtable for each computername and add to the nodes array
$nodes+=@{
NodeName="$computer"
PSDscAllowPlainTextPassword=$true
}
}#end foreach
#add the nodes to AllNodes
$configData.AllNodes=$nodes
#you will be prompted to enter a credential
Write-Host "Enter Admin credentials" -ForegroundColor Green
RemoveWorkspace $Computers -configurationdata $configData -outputpath C:\Temp\DeleteDirs\$computer
Start-DscConfiguration -Path C:\Temp\DeleteDirs\$computer -Wait -Verbose -Force
经过一番调查,我已经解决了我的问题。我将在稍后发布最新代码
【问题讨论】:
-
您是说您不想/不能使用 DSC 脚本资源来执行发布的操作?
-
我无法使用 DSC 文件资源执行操作。
-
不基于文档显示的与 DSC 文件资源功能相关的内容。然而,这就是 DSC 自定义资源和脚本资源退出的原因。去做那些不是 OOBE 的事情。然而,从技术上讲,我明白你的意思。如果我看到来自供应商的文件提供程序,我们会自动假设它的文件夹很好,但情况并非总是如此。需要注意的是,如果您开始尝试使用通配符/多文件类型过滤器,那么至少现在您会遇到相同的建议。
标签: powershell dsc