mark_chuman
Hot Shot
Hot Shot

Usually the desire is to have more $$$$, but I'm interested in removing them

Jump to solution

Anyone have ideas on the best way to use the information exported with this command in a create-cluster or set-cluster?

Get-Cluster -name $Cluster | Select Name, HAEnabled, HAFailoverLevel, DrsEnabled, DrsMode | Export-Csv -NoTypeInformation -UseCulture -Path .\$Cluster.csv

Having a tricky time with getting the variables back into a new-cluster or set-cluster command.  For example, my csv is here:

"Name","HAEnabled","HAFailoverLevel","DrsEnabled","DrsMode"

"ClusterName","True","1","True","FullyAutomated"

The -HAAdmissionControlEnabled parameter for example in set-cluster or create-cluster has a $ sign that is making it tricky to get the value in my csv back in

set-cluster -cluster $Cluster -HAEnabled:$True -HAAdmissionControlEnabled:$True -confirm:$False

Comes out something like this when I put it together

set-cluster -cluster $cluster -HAEnabled:$$myvaluefromcsv

Smiley Happy

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Splatting is a good way to bypass this (especially for switches)

Import-Csv yourcsv.csv | %{

   $splat = @{

      Cluster = $_.Name

      HAEnabled = [boolean]$_.HAEnabled

      HAAdmissionControlEnabled = [boolean]$_.HAAdmissionControlEnabled

      Confirm = $false

   }

   Set-Cluster @splat

}

During the export the Boolean values will be converted to a [string], saying true or false.

When you import the CSV you will be getting a [string], but with a Boolean cast the string is converted to a Boolean.

Try like this


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership

Splatting is a good way to bypass this (especially for switches)

Import-Csv yourcsv.csv | %{

   $splat = @{

      Cluster = $_.Name

      HAEnabled = [boolean]$_.HAEnabled

      HAAdmissionControlEnabled = [boolean]$_.HAAdmissionControlEnabled

      Confirm = $false

   }

   Set-Cluster @splat

}

During the export the Boolean values will be converted to a [string], saying true or false.

When you import the CSV you will be getting a [string], but with a Boolean cast the string is converted to a Boolean.

Try like this


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mark_chuman
Hot Shot
Hot Shot

Awesome.  Many thanks as always for the help.  Would I also be able to slip in variables defined earlier in the script and not contained in the csv?

Import-Csv yourcsv.csv | %{

   $splat = @{

      Location = $variabledefinedearlier

      Cluster = $_.Name

      HAEnabled = [boolean]$_.HAEnabled

      HAAdmissionControlEnabled = [boolean]$_.HAAdmissionControlEnabled

      Confirm = $false

   }

   Set-Cluster @splat

}

Thanks!!!!!

0 Kudos
mark_chuman
Hot Shot
Hot Shot

I got it.  Thanks again Luc, this is a neat little way to get around this.

0 Kudos
LucD
Leadership
Leadership

Sure, you should be able to use any variable in the assignments in the splat block


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mark_chuman
Hot Shot
Hot Shot

Interesting wrinkle on this one though.  So, if you pickup the cluster settings and haenabled or drsenabled are set to "False", the splat process (boolean?) processes those as "True".  Assuming it is stating True or False based on if there is a value there.

0 Kudos
mark_chuman
Hot Shot
Hot Shot

my band-aid:

   $splat = @{

   

        Name = $_.Name

        HAEnabled = If ($_.HAEnabled -eq "False") {$False} else {[Boolean]$_.HAEnabled}

 

        DrsEnabled = If ($_.DrsEnabled -eq "False") {$False} else {[Boolean]$_.DrsEnabled}

0 Kudos
LucD
Leadership
Leadership

Yes, my bad on the Boolean casting, that is a known "issue".

An alternative is to use the System.Convert method

convert.jpg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos