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.
Asked
Active
Viewed 697 times
3
-
Are you compiling the configuration on the target node? – TravisEz13 Feb 10 '17 at 02:33
-
Yes, I'm using Azure DSC Extension for that. – Max Feb 10 '17 at 08:20
1 Answers
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'
}
}
}
}

TravisEz13
- 2,263
- 1
- 20
- 28
-
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.``` – Max Feb 12 '17 at 06:04