0

我在尝试使用 Desired State Configuration (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
            }
        }
    }
}
}
4

1 回答 1

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
        }
    }
于 2014-05-21T18:45:40.507 回答