我遇到了尝试使用所需状态配置(DSC)的问题。我正在使用脚本资源,当我运行Start-DscConfiguration -Wait -Verbose -Path .\blah
时,无论如何都会跳过该步骤。我已将TestScript设置为False,它仍然会跳过该步骤。有谁知道为什么它会跳过这些步骤?这就是我在做的事情:
http://technet.microsoft.com/en-us/library/dn249912.aspx
configuration disk
{
node $env:computername
{
Script disk
{
SetScript = {
ADD-Content -Path "c:\disk.txt" "List Disk"
$listDisk = (Diskpart /s c:\disk.txt);
$c = 0;
$dname = "", "_d_data" , "_e_wmapps", "_f_wmlogs", "_s_swapfile";
for($i = 0; $i -le ($listDisk.Count) ; $i++)
{
if($listDisk[$i] -match "Disk [0-99]")
{
$dn = $dname[$c];
if ($c -eq 0)
{
Add-Content -Path "C:\hrd.txt" "Select Volume 0"
Add-Content -Path "C:\hrd.txt" "assign letter=B"
}
else
{
Add-Content -Path "C:\hrd.txt" "Select Disk $c"
Add-Content -Path "C:\hrd.txt" "CREATE PARTITION PRIMARY"
}
$c++
}
}
diskpart /s "c:\hrd.txt"
Remove-Item "c:\disk.txt"
Remove-Item "c:\hrd.txt"
}
GetScript = {return @{Name = "Disk"}}
TestScript =
{
$obj = Get-WmiObject "Win32_DiskDrive" -Filter "Partitions=0"
if($obj.count -eq 0)
{
[bool]::TrueString
}
else
{
[bool]::FalseString
}
}
}
}
}
答案 0 :(得分:0)
发现我的错误。在我调用布尔字符串的地方,它应该是保留变量$ true或$ false
我在这里找到了我的信息: http://powershell.org/wp/2014/03/13/building-desired-state-configuration-custom-resources/
TestScript =
{
$obj = Get-WmiObject "Win32_DiskDrive" -Filter "Partitions=0"
if($obj.count -eq 0)
{
$true
}
else
{
$false
}
}