Hi All,
Having a bit of an issue with the above. I want a script that can enable\disable HA and set DRS to MaunalAutomated. I have seen a number of examples out there but I dont appear to be able to find anything that lets me pick a single cluster to perform this on.
What I would like to do is hae a script that pulls back a list of the clusters on a VC (get-cluster) but then provides me with a list of these clusters that I can pick from and then pick what action to take next (as in disable ro enable HA) Or even somthing where I have to just provide the cluster name?
As you might have guessed, I am quite new to PowerCLI..
Thanks
Not too sure what exactly you want to do?
Picking a cluster from a list could be done like this.
Write-Host "You picked $($cluster.Name)"
Does that resemble what you had in mind?
In a similar way, you could pick an action.
$selected = $actions | Out-GridView -OutputMode Single
Write-Host "You picked $selected"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not too sure what exactly you want to do?
Picking a cluster from a list could be done like this.
Write-Host "You picked $($cluster.Name)"
Does that resemble what you had in mind?
In a similar way, you could pick an action.
$selected = $actions | Out-GridView -OutputMode Single
Write-Host "You picked $selected"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for replying.
So here is what I am trying to do.
I have a virtual centre with 15 clusters. I want to build a script that will, for example, disable HA on a single cluster. Now, I can wrote the script to disable HA, thsat is not a problem. What I need is a way of the script queryiung the VC and then letting me pick a single cluster to run the script on. Does that make sence?
Thanks
If you are connected to all those vCenters, that is what Get-Cluster is doing.
Is the Out-GridView not an option?
Or do you actually want to compose and display a Windows GUI/Form?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, this is going to be me not understanding how this works. So i run the command and I get the following:
How do I then pick one of the to feed it back in to the script?
You select 1 line and then click <ok> on the form
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure how I missed that.. Thanks..
Now I need to pull that through to disable HA. This is what I have so far.
---------------------
Import-Module VMware.PowerCLI
Connect-VIServer
$cluster = Get-Cluster | Out-GridView -OutputMode Single
Write-Host "You picked $($cluster.Name)"
$cluster | Set Cluster -HAEnabled:$false
-----------------------
Now this is not working and I sure that you are looking at it and laughing but any chance you can tell me how to correct this?
Not really, that should work.
Are you getting any error messages?
Did you get the "You picked..." message?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I get the following:
You forgot the dash between Set and Cluster
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks again..
One ore thing. I am starting my script with the following:
Import-Module VMware.PowerCLI
Connect-VIServer
Is there a way of getting the script to check if, 1, the module has already been loaded, and 2, if it is already connected to a VC and if both have these ahve already been done, ignore them in the script?
When you are using PS v4 or higher and a recent PowerCLI version, you don't even need that Import-Module.
The PS engine will 'know' all the cmdlets in all the modules that are accessible via $env:PSModulePath.
The moment you use a cmdlet from a module that is not yet loaded, the PS engine will automatically load the module.
It is called module autoloading.
All connections to vSphere servers are kept in a variable $global:DefaultViServers.
The last connection is kept in $global:DefaultVIServer.
You can use the variable to check if a certain connection is already there.
Something like this
if($global:DefaultVIServers.Name -notcontains $vcName){
Connect-VIServer -Server $vcName
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference