Search code examples
dsc

Desired State Configuration Hash tables


I am running into an issue trying to use the Desired State Configuration (DSC). I am using the script resource and when I run the Start-DscConfiguration -Wait -Verbose -Path .\blah it skips the step no matter what. I have set the TestScript to False and it still skips the step. Would anyone know why it's skipping the steps? Here is what I am doing:

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
            }
        }
    }
}
}

Solution

  • Found my mistake. Where I was calling a Boolean string, it should have been a reserved variable $true or $false

    I found my info here: 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
            }
        }