2

Is it possible to initialize all attached disks to multiple VMs with a single DSC configuration? For example if VM1 has 1 disk attached that DSC configuration would initialize that disk as disk F, VM2 has 2 disks, so the very same DSC configuration would attack disks as F and G. The idea is to reuse that configuration file for multiple VMs with a variable amount of disks without getting errors.

2
  • Are you compiling the configuration on the target node? Commented Feb 10, 2017 at 2:33
  • Yes, I'm using Azure DSC Extension for that. Commented Feb 10, 2017 at 8:20

1 Answer 1

4

This should work if you are compiling locally. Since the language allows imperatively building the declared state. You can query the disks and set the state.

The assignment of drive letters in my sample is rather crude. You should improve it as well.

This uses xStorage which can be found on the PowerShell Gallery

Configuration disks
{
  $DriveLetters = 'DEFGHIJKLMNOPQSRT'
  Import-DscResource -ModuleName xStorage

  Node localhost
  {
    Get-Disk | Where-Object {$_.NumberOfPartitions -lt 1} | Foreach-Object {
      Write-Verbose "disk($($_.Number))" -Verbose
      xDisk "disk($($_.Number))"
      {
        DriveLetter = $DriveLetters[$_.Number]
        DiskNumber = $_.Number
        FSFormat = 'NTFS'        
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Fails with different error: The DSC Extension received an incorrect input: Compilation errors occurred while processing configuration 'disks'. Please review the errors reported in error stream and modify your configuration code appropriately. Index operation failed; the array index evaluated to null. Exception calling "InvokeWithContext" with "2" argument(s): "Index operation failed; the array index evaluated to null." Index operation failed; the array index evaluated to null.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.