Script to reconfigure the cluster HA

Hello

Here, I wrote a script that changes the PA according to the entry. However I have a few questions because of this script is the error handling...

=========================================================

Param ($VCserv, $VCuser, $VCpass, $Clust, $HAinput, $cl, $Snapin, $i, $n)

$Snapin = Get-PSSnapin -recorded

for ($i = 0; $i - 5; $i ++) {}

If ($Snapin [$i] .name - eq "VMware.VimAutomation.Core")

{

$n = 1

}

}

If ($n - eq. 1)

{Write {"are component snap"}}

on the other

{Add-PSSnapIn VMware.VimAutomation.Core}

  1. Connect to vCenter Server

#

*

SE connect-VIServer $VCserv -user $VCuser -password $VCpass

*

  1. Verify the existence of the Cluster

#

$cl = get-cluster -name $Clust

  1. Check $HAinput = 0 or 1

  1. Error of not

If ($HAinput - eq '0')

{ Set-Cluster -Cluster $cl HAEnabled - 0 -confirm: $false}

on the other

{Set-Cluster -Cluster $cl -HAEnabled 1 -confirm: $false}

  1. Disconnect from the server vCenter

*

disconnect-viserver -confirm: $false

================================================================

Here, I want to insert where it should be able to check the settings and then performs the action of the error handling.

You guys could help me check the parameters or arguments.

Thanks,

* Priya

*

I'm not sure that I understood what you want, but if it is the validation of the parameters in a function, you can do the following 100%.

(1) to define the type of the parameter


param ([string]$param1, [int]$param2)
...

PS will give an error message when the type of the parameters passed is not correct.

(2) check that the parameter is not empty


param([string]$param1=$(Throw "Parameter missing: -Param1 string"),
          [int]$param2=$(Throw "Parameter missing: -Param2 int"))
....

(3) If you need more specific tests on your settings, you must include you this logic in your script.

Note that the Param statement in PowerShell v2 has been revised and is now a number of additional options.

Tags: VMware

Similar Questions

  • How to cancel the configuration and reconfigure the cluster HA.

    How to cancel the configuration and reconfigure the cluster HA.

    complete step by step to do this...

    VPX is just the vcenter only. You must follow the KB and watch the folder for example:

    Info NŒUD 6 Nov 14:02:06 Mar 2007
    By: FT/Agent on the Node: servername3
    MESSAGE: Servername1 Agent stopped
  • Script to keep the monitoring parameters of VM to 'Disable '.

    I'm looking for a way to create a script to keep the monitoring parameters of VM to 'Disable '. Here's my question:


    Symantec ApplicationHA requires that the 'Follow-up of the VM' option under VMware HA fixed "VM and Application monitoring. If I set this parameter as already said, all the virtual machines in the cluster gets 'Use the parameters of Cluster' and they are part of the surveillance with risk of unexpected VM resets. So I'm going to select 'Disable' for all virtual machines leaving only a couple of VMs who must actually followed even with a reset the virtual machine.

    Challenge

    1. How to get this applies with a script. There are hundreds of virtual machines, I need to adjust the monitoring to disable.
    2. Virtual machines continue to add to the cluster and they get 'use the Cluster setting' default and someone had to keep track of these and follow up on "Disable" the value manually.

    I want to know if there is a way, it can be script to change the setting "VM Monitoring" to "Disable" as well as the new creation of VM.

    Thanks in advance for your help.

    VM Monitoring.png

    Hello, vSphereUser7-

    Mhmm... And updated two values I mentioned that you should use in your environment?

    0) the name of the folder that contains the virtual machines to keep tracking enabled on

    (1) the name of the cluster whose update settings

    And, looking at the code, it would have a degree more to add in the DasSettings of the specification of the config.  This will only act on the virtual machines for which the settings of the virtual machine for monitoring have been changed in the HA cluster settings, I see.  So, it can act on all the virtual machines you want.

    I saw your other thread at http://communities.vmware.com/message/1858996#1858996, where refer you to the post of Damian Karlson on the (http://damiankarlson.com/2011/01/13/managing-vmware-has-vm-monitoring-powercli/).  Method of Damian to disable monitoring on a VM would be a nice way to do it.  In developing his technique and performing the config for multiple virtual machines, you could do it like:

    $strMyClusterName = "myCluster"## get the .NET View object of the cluster, with a couple of choice properties$viewMyCluster = Get-View -ViewType ClusterComputeResource -Property Name, Configuration.DasVmConfig -Filter @{"Name" = "^${strMyClusterName}$"}
    
    ## make a standard VmSettings object$dasVmSettings = New-Object VMware.Vim.ClusterDasVmSettings -Property @{    vmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings -Property @{        enabled = $false        vmMonitoring = "vmMonitoringDisabled"        clusterSettings = $false    } ## end new-object} ## end new-object
    
    ## create a new ClusterConfigSpec object with which to reconfig the cluster$oClusterConfigSpec = New-Object VMware.Vim.ClusterConfigSpec## for each VM View, add a DasVmConfigSpec to the ClusterConfigSpec objectGet-View -ViewType VirtualMachine -Property Name -SearchRoot $viewMyCluster.MoRef | %{    $viewThisVM = $_    ## the operation for this particular DasVmConfigSpec; if a spec already exists for the cluster for this VM, "edit" it, else, "add" it    $strOperationForThisVM = if ($viewMyCluster.Configuration.DasVmConfig | ?{($_.Key -eq $viewThisVM.MoRef)}) {"edit"} else {"add"}    $oClusterConfigSpec.DasVmConfigSpec += New-Object VMware.Vim.ClusterDasVmConfigSpec -Property @{        operation = $strOperationForThisVM     ## set the operation to "edit" or "add"        info = New-Object VMware.Vim.ClusterDasVmConfigInfo -Property @{            key = [VMware.Vim.ManagedObjectReference]$viewThisVM.MoRef            dasSettings = $dasVmSettings        } ## end new-object    } ## end new-object} ## end foreach-object
    
    ## reconfigure the cluster with the given ClusterConfigSpec for all of the VMs$viewMyCluster.ReconfigureCluster_Task($oClusterConfigSpec, $true)
    

    I simplified the creation of an object a little and added specifications of configuration of computers all virtual config spec a single cluster, so that just ReconfigureCluster() only once.

    It is important to note that the specifications being created to update the monitoring parameters given VM can have a type of operation of 'Add' or 'change '.  If we changed the parameter a VM in the HA settings for the cluster, it creates an Configuration.DasVmConfig object for this virtual machine.  The functioning of these virtual machines must be 'Edit '.  Otherwise, you have to 'Add '.  See the commented line in the code that deals with this topic.

    If you do not have that correct property creating the specification, you will get an error (in the vSphere client) as the cluster reconfig task tries to complete: "specified parameter was not correct."

    Copy the following code disables tracing for all the virtual machines in the given cluster (adjust the name of cluster variable before you run).  You could exclude the virtual machines that you want to continue to follow (or change in the GUI at will), or run a similar code to allow follow-up again for desire, VMs, or...

    How does do for you?

  • Ability of the cluster script

    Hello

    I need help for the correct syntax for the line 61-63 in the attached script and get the correct values for line 56-57 a per cluster basis.

    I want to remove the comma for line 61-63 results, I have added the (), 0 according to the other lines, but clearly, I can't understand the correct positioning in this case to use. For line 56-57 i also try to get the details on a per cluster of basis for the previous day.

    Hope someone got some recommendation and all the other tips to improve the script.

    Thank you

    Johan

    Sorry try to put the part of the value of these lines in parentheses:

    Add-Member-pass NoteProperty 'ClusterCPUUsageAverage' ('{0:N1}' f - $stat.average).

    Let me know if it works for you.

  • Script to pull the last timestamp spend all hosts in a cluster?

    Hi all

    Lately I have seen an issue where my host 5.1 logging abruptly stops and the other remote access to every host I have no way of knowing what happened.

    Is it possible to account for the last, for example hostd.log timestamp for each host in a cluster?

    Thank you

    Tony

    Try something like this

    foreach($esx in Get-Cluster -Name MyCluster | Get-VMHost){  $log = Get-Log -Key hostd -VMHost $esx  $esx | Select Name,@{N="Last entry";E={[datetime]($log.entries[-1].Split(' ')[0])}}}
    

    But be aware that fetch a newspaper of the ESXi could take some time.

    The script needs get the full log, to be able to extract the last line

  • PowerCLI script to list cluster name, comments, and host in the Cluster name

    Greetings,

    I need script to the cluster name, comments list Powercli and ESXi Hostnames in the Cluster, and then export to a csv file

    Thank you

    I suppose you want the name of the cluster, host name and comments for all your virtual machines. This information, you can export it to a file .csv as follows:

    Get-VM |
    Select-Object -Property @{N="VM";E={$_.Name}},
    VMHost,
    @{N="Cluster";E={$_.VMHost.Parent.Name}},
    @{N="Guest";E={$_.Guest.OSFullName}} |
    Export-Csv -Path VMInfo.csv -NoTypeInformation -UseCulture
    
  • Script of VM inventory for VM name with the location, the name of the Cluster and data storing total size and free space left in DS.

    Hello

    I wanted to collect script inventory VM VM name with location, name of the Cluster and data store total size and free space left in Datastore.I have script but his mistake of shows during its execution. Any help on this will be apreciated.

    Thank you

    VMG

    Error: -.

    Get-view: could not validate the argument on the parameter "VIObject". The argument is null or empty. Provide an argument that is not null or empty, and then try
    the command again.
    E:\script\VM-DS-cluster.ps1:7 tank: 20
    + $esx = get-view < < < < $vm. Runtime.Host - name of the Parent property
    + CategoryInfo: InvalidData: (:)) [Get-view], ParameterBindingValidationException)
    + FullyQualifiedErrorId: ParameterArgumentValidationError, VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

    Get-view: could not validate the argument on the parameter "VIObject". The argument is null or empty. Provide an argument that is not null or empty, and then try
    the command again.
    E:\script\VM-DS-cluster.ps1:8 tank: 24
    + $cluster = get-view < < < < $esx. Parent - the name of the property
    + CategoryInfo: InvalidData: (:)) [Get-view], ParameterBindingValidationException)
    + FullyQualifiedErrorId: ParameterArgumentValidationError, VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

    Get-view: could not validate the argument on the parameter "VIObject". The argument is null or empty. Provide an argument that is not null or empty, and then try
    the command again.
    E:\script\VM-DS-cluster.ps1:9 tank: 24
    + += get-view $report < < < < $vm. Store data-name of the property, summary |
    + CategoryInfo: InvalidData: (:)) [Get-view], ParameterBindingValidationException)
    + FullyQualifiedErrorId: ParameterArgumentValidationError, VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

    It seems that your copy/paste lost some.

    I have attached the script

  • Equivalent of PowerShell for script following VBScript determine the active node of the cluster?

    Hello world

    I wonder if there is another similar Powershell script that can determine the currently active node of an MSCS?

    What follows is done on VBScript

    strClusterWMINameString = "winmgmts:\\ExchangeServerCluster01\root\cimv2"
    Set objWMISvc = GetObject( strClusterWMINameString )
    Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
    For Each objItem in colItems
        strComputerName = objItem.Name
        WScript.Echo "The Cluster " & strClusterWMINameString & " active node is " & strComputerName
    Next
    
    
    

    Any kind of help is appreciated.

    Thank you.

    In PowerShell, you can do this with:

    (Get-WmiObject Win32_ComputerSystem - SIEXCLU01 of the computer). Name

    Best regards, Robert

  • How to identify the name of the cluster to run the createresourcepool script?

    I want to manage the resource in ESX 4.1 Pool.

    And fortunately, I found a script from here, written by William Lam in 28/11/09.

    Lam, Hello, how are you?

    I want to test your code, but I don't know how to use it.

    I mean, I have a machine ESX, alone, with host name datastore1.vlab.iu.hio.no, that should not be called a cluster.

    But if I want to run your script, I should offer you a cluster name. So, what is the name of the cluster here?

    Thank you.

    Hello

    If you're referring to the createResourcePool.pl script, the documentation provides an example on how to use the vSphere SDK for Perl script.

    ./createResourcepool.pl--serveur reflex.primp - industries.com - username primp - cluster "R & D" - resourcepool rp6

    You will need to provide the name of the vCenter cluster where you want to create the pool of resources, in the example I created a pool of resources called "rp6" to the title of the group 'R & D'.

    If you are just to handle a crowd of ESX (i) autonomous which looks like you are, then you will need some modification of the script to allow you to create a pool of resources directly on the host ESX (i). Attached is a quick tweak to the script existing and all what you need to do is to connect directly to your host and specify the name of the list of resources you want to create. It assumes that there is no existing resource pool and this will be attached to the main world 'resourcePool' which is there by default, but you don't see it.

    Here's the syntax:

    . /RP.pl - Server himalaya.primp - industries.com - username root resourcepool - myRP

  • Reconfiguration of HA at the Cluster level

    I have a warning message indicating that HA started tipping in one of my groups. The difficulty that I found was to disable/re-enable HA to the cluster level. Does have an impact to the production host? Or is it possible safe at any time?

    Disabling HA empowerment on the cluster again will have no impact for the virtual machines or the hosts and can be performed without risk.

  • Script of statistics VM does not show the good name of the Cluster.

    I tried to add a column to display the cluster virtual machine which is, but appearently I hurt him.  The column lists a cluster, but it's evil, and it's the same for all virtual machines.

    #####################################
    # Statistics virtual machine VMware #.
    #####################################

    function {VM-statavg ($StatStart, $StatFinish, $vmImpl, $statId)
    $stats = $vmImpl | Get-stat - Stat $statId - intervalmin 120 - Maxsamples 360'
    -Launch $StatStart - finishing $StatFinish
    $statAvg = "{0, 9:.00 #} ' f ($stats |) Measure - Object value - average) subject
    $statAvg
    }
    # Eve report
    $DaysBack = 30 # number of days to return back
    $DaysPeriod = 30 # number of days in the interval
    $DayStart = (get-Date). Date.AddDays(-$DaysBack)
    $DayFinish = (get-Date). Date.AddDays (-$DaysBack + $DaysPeriod).addminutes(-1)
    # Report for the previous week
    $DaysBack = 7 # number of days to return back
    $DaysPeriod = 7 # number of days in the interval
    $WeekStart = (get-Date). Date.AddDays(-$DaysBack)
    $WeekFinish = (get-Date). Date.AddDays (-$DaysBack + $DaysPeriod).addminutes(-1)
    $report = @)
    Get - vm | Sort name | % {
    $vm = get-view $_.ID
    $vms = "" | Select-Object VMName Hostname, Cluster, MonthAvgCpuUsage, WeekAvgCpuUsage, VMState, TotalCPU, TotalMemory, MonthAvgMemUsage, WeekAvgMemUsage, TotalNics, ToolsStatus, ToolsVersion
    $vms. VMName = $vm. Name
    $vms. Host name = $vm.guest.hostname
    $vms. Cluster = $Cluster.Name
    $vms. MonthAvgCpuUsage = VM-statavg $_ $DayStart $DayFinish "cpu.usage.average".
    $vms. WeekAvgCpuUsage = VM-statavg $_ $WeekStart $WeekFinish "cpu.usage.average".
    $vms. VMState = $vm.summary.runtime.powerState
    $vms. TotalCPU = $vm.summary.config.numcpu
    $vms. TotalMemory = $vm.summary.config.memorysizemb
    $vms. MonthAvgMemUsage = VM-statavg $_ $DayStart $DayFinish "mem.usage.average".
    $vms. WeekAvgMemUsage = VM-statavg $_ $WeekStart $WeekFinish "mem.usage.average".
    $vms. TotalNics = $vm.summary.config.numEthernetCards
    $vms. ToolsStatus = $vm.guest.toolsstatus
    $vms. ToolsVersion = $vm.config.tools.toolsversion
    $Report += $vms
    }

    $Report | ConvertTo-Html-title "VMware Virtual Machine statistics" - body "< H2 > VMware Virtual Machine statistics.» "< / H2 > ' | Out-file - add $filelocation

    Looks like you forgot to get the cluster.

    The first lines of the loop must be something like this

    ...

    Get - vm | Sort name | % {
    $vm = get-view $_.ID

    $cluster = get-Cluster - VM $_

    ....

  • Script to change the tools upgrade policy

    Someone at - it script PowerCLI to change the strategy to upgrade VMware Tools on all the virtual machines in a cluster or a data center?

    Thank you

    John

    Hello, jconidesGP-

    You should be able to use a VirtualMachineConfigSpec and reconfigure the given VMs as you wish (the vNoob talking about something like this earlier in this post).   A similar decision and it for a cluster, would look like:

    ## create the config spec$spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{    Tools = New-Object VMware.Vim.ToolsConfigInfo -Property @{        ToolsUpgradePolicy = "UpgradeAtPowerCycle"    }}
    
    ## get all of the VMs in the given cluster, and reconfigure them with the config specGet-Cluster myCluster | Get-VM | %{$_.ExtensionData.ReconfigVM_Task($spec)}
    

    What to do for you?

  • [Helix 2nd generation] Reconfigure the tablet buttons

    Hello world

    Is it possible to reconfigure the keys on the Tablet, specifically the autorotate button on / off? Would love to instead assign a script (file * .bat) to what I wrote to switch on and outside touch screen (by release ultimate palm).

    Thanks for your help!

    Moritz

    FYI: ATNSOFT Key Manager does the work!

    SOLVED.

  • Dynamic resizing of the cluster

    Is is possible to resize the cluster with buttons dynamically? I mean during run mode? If it's possible could you give me some suggestions?

    Kind regards

    Izabela

    Oh... Sorry... you may need to enable scripting.

    See here: http://decibel.ni.com/content/docs/DOC-4973

  • Looking for a Script to check the current status of the VM tools based on resource pool (customer name)

    Hi all and

    LucD The champion!

    I'm looking for a power-cli script to verify the State of VM-tools of all the virtual machines in the cluster multi environment. Could you please help me on this. It would be really appreciated.

    Thank you. in advance.

    Concerning

    Nauman

    Try like this

    $report = @)

    {foreach ($cluster Get-cluster)

    foreach ($rp in Get-ResourcePool-location $cluster) {}

    foreach ($vm in (Get-VM-location the $rp)) {}

    $report += get-disk hard - VM $vm |

    Select @{N = "Cluster"; E = {$cluster. Name}},

    @{N = "ResourcePool"; E = {$rp. Name}},

    @{N = "VM"; E = {$vm. Name}},

    @{N = 'Tools status'; E = {$vm. ExtensionData.Guest.ToolsStatus}},

    @{N = 'HD'; E={$_. Name}},

    @{N = "Datastore"; E={($_. Filename.Split(']') [0]). TrimStart('[')}},

    @{N = 'Filename'; E={($_. Filename.Split('_') [1]). "Split('/') [0]}},"

    @{N = 'Path VMDK'; E={$_. File name}}.

    @{N = "Format"; E={$_. StorageFormat}},

    @{N = ' Type'; E={$_. DiskType}},

    @{N = "CapacityGB"; E={$_. CapacityGB}}

    }

    }

    }

    $report | Export Csv C:\temp\report.csv - NoTypeInformation - UseCulture

Maybe you are looking for