I’m working with a powershell function that looks like the following:
set-ceblueprint
-InstanceId $machine.id
-InstanceType "t3.2xlarge"
-SubnetIDs "subnet-0d94c365043c93ac8"
-SecurityGroupIDs "sg-0836f28e55dd2c349"
-Disks @(@{type = "SSD"; name = "c:0"}, @{type="SSD"; name = "e:0"})
-Tags @{Environment = "prddr"; ITOwner = "Platform Engineering"; BusinessOwner = "IT"; ManagedBy = "CloudEndure"; ProjectCode = "Support-DR"}
-confirm:$false
The parameter -Disk accepts an array of hashtables ([System.Collections.Hashtable[]]$Disks), and the length will depend on how many disks a given machine might have. I'm able to pull the number of disks and my $variable that contains the number looks like the following:
type name
---- ----
SSD c:0
SSD e:0
I'd like to be able to pass in a variable into -Disks so that it dynamically builds depending on what machine I'm creating blueprint for, example of where I'm at:
<pre><code>$machines = get-cemachine 83b8f5ad-308f-4b70-805f-55e9a8f19f2c
foreach ($machine in $machines)
{
$numberofdisks = $machine.sourceProperties.disks | select-object @{Name = "type"; Expression = { "SSD" } },name
$diskhash = $null
$diskhash = @{}
foreach ($disk in $numberofdisks) {$diskHash.add($disk.name,$disk.type)}
$diskHash
set-ceblueprint
-InstanceId $machine.id
-InstanceType “t3.2xlarge” -SubnetIDs "subnet-0d94c365043c93ac8"
-SecurityGroupIDs “sg-0836f28e55dd2c349” -Disks $diskhash
-Tags @{Environment = “prddr”; ITOwner = “Platform Engineering”; BusinessOwner = “IT”; ManagedBy = “CloudEndure”; ProjectCode = “Support-DR”} -confirm:$false }
The cmdlet doesn’t like the input for $diskhash Hoping for some guidance here, a bit of a newb and am struggling to come up with correct method to use.