I need help passing the correct parameters to my command..
For this example the value of the HAEnabled in the xml file is “true” a text string.
New-Cluster -Location $_.Datacenter -Name $_.Cluster -HAEnabled ($_.HAEnabled)
I’ve tried doing: $cHAE = http://System.Convert::ToBoolean($_.HAEnabled) and then using the $cHAE in the command = this did not work
I’ve also tried casting it directly in the command like this: -HAEnabled $_.HAEnabled = this did not work
If I do this: -HAEnabled $true = this works but of course I’m reading a file with multiple cluster definitions in it.
Hopefully one of you have run accros this and has a solution that will work for how I cast stuff in general.
Thanks in advance
The file contents look like this (Dataclust.xml)
DataCenter : MyDatacenter
Cluster : MyCluster
HAEnabled : True
HAFail : 1
DRSAuto : FullyAutomated
DRSEnable : True
DrsMode : FullyAutomated
HAAdm : True
VMSwap : WithVM
HARestart : Medium
HAIso : DoNothing
Part of the script below:
$Global:clust = Import-Clixml c:\scripts\DataClust.xml
$clust | foreach-Object{
New-Cluster -Location $_.Datacenter -Name $_.Cluster -DrsMode $_.DRSMode -DrsAutomationLevel $_.DrsAuto -HAEnabled ($_.HAEnabled) -HAAdmissionControlEnabled ($_.HAAdm)
-HAFailoverLevel $_.HAFail -HARestartPriority $_.HARestart -DrsAutomationLevel $_.DrsAuto -HAIsolationResponse $_.HAIso -VMSwapfilePolicy $_.VMSwap -DrsEnabled $_.DRSEnable -DrsMode $_.DRSMode
}
Sorry, my typo. Should have said
New-Cluster -Location $_.Datacenter -Name $_.Cluster -HAEnabled:($_.HAEnabled -eq "true")
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do this
New-Cluster -Location $_.Datacenter -Name $_.Cluster -HAEnabled ($_.HAEnabled -eq "true")
The comparison will return $true or $false depending if the variable contains respectively "true" or "false".
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried the compare but I get this error ?
New-Cluster : A positional parameter cannot be found that accepts argument 'False'.
At C:\SCRIPTS\VMmigrationAF.ps1:30 char:14
+ New-Cluster <<<< -Location $_.Datacenter -Name $_.Cluster -DrsMode $_.DRSMode -DrsAutomationLevel $_.DrsAuto`
+ CategoryInfo : InvalidArgument: ( , ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,VMware.VimAutomation.VimAutomation.Commands.NewCluster
Code snippet
New-Cluster -Location $_.Datacenter -Name $_.Cluster -DrsMode $_.DRSMode -DrsAutomationLevel $_.DrsAuto`
-HAEnabled ($_.HAEnabled -eq "True")
#-HAAdmissionControlEnabled ($_.HAAdm -eq "true")`
-HAFailoverLevel $_.HAFail -HARestartPriority $_.HARestart `
-HAIsolationResponse $_.HAIso -VMSwapfilePolicy $_.VMSwap -DrsEnabled ($_.DRSEnable -eq "true")
Sorry, my typo. Should have said
New-Cluster -Location $_.Datacenter -Name $_.Cluster -HAEnabled:($_.HAEnabled -eq "true")
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That helped alot
But now I'm getting this error: (Even though its creating most of the clusters)
New-Cluster : 3/13/2010 9:22:56 PM New-Cluster 0B40DFB1-F9A7-4320-AAD0-5F56098669DA Exception of type 'VMware.
VimAutomation.Types.InvalidArgumentException' was thrown.
At C:\SCRIPTS\VMmigrationAF.ps1:30 char:15
+ New-Cluster <<<< -Location $_.Datacenter -Name $_.Cluster -DrsMode $_.DRSMode -DrsAutomationLevel $_.DrsAuto `
+ CategoryInfo : InvalidArgument: ( , InvalidArgumentException
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckClusterHaFeatures_InvalidHaState,VMware.VimAutomation.Vi
mAutomation.Commands.NewCluster
Not yet sure what is throwing it
New-Cluster -Location $_.Datacenter -Name $_.Cluster -DrsMode $_.DRSMode -DrsAutomationLevel $_.DrsAuto `
-HAAdmissionControlEnabled: ($_.HAAdm -eq "True") -HAEnabled: ($_.HAEnabled -eq "True")`
-HAFailoverLevel $_.HAFail -HARestartPriority $_.HARestart `
-HAIsolationResponse $_.HAIso -VMSwapfilePolicy $_.VMSwap -DrsEnabled: ($_.DRSEnable -eq "true")
Ok I see it only happens where the records have HAEnabled = False
What I finally did to correct the issue was to do a set-cluster after the fact as the new-cluster cmdlet seems to have a flaw in it (or so is my current thought)
Set-Cluster -Cluster $_.Cluster -HAEnabled:($_.HAEnabled -eq "True") -Confirm:$False