get data on the performance of the virtual machine

Hello community,

I am trying to obtain performance data from a virtual machine using the following code:

//create start & stop time 
var end = new Date(); // now
var start = new Date();
start.setTime(end.getTime() - 3600000); // 1h before end
//create a querySpec for one entity
var querySpec = new Array();
querySpec.push(new VcPerfQuerySpec());
querySpec[0].entity = VM.reference; //set entity of workflow VM
querySpec[0].startTime = start;
querySpec[0].endTime = end;
//creteate PerfMetricID for one metric
var PM = new VcPerfMetricId();
PM.counterId = 2;
PM.instance = "";
var arrPM = new Array();
arrPM.push(PM);
querySpec[0].metricId = arrPM; //assign PerfMetric to querySpec
querySpec[0].intervalId = 20;
querySpec[0].format = "csv";

var CSV = VM.sdkConnection.perfManager.queryPerf(querySpec);  // query PerformanceManager
System.log (CSV);// show if type is OK
//show properties
System.log (CSV.entity);
System.log (CSV.value);
System.log (CSV.sampleInfoCSV);
System.log (CSV.dynamicProperty);

The workflow is valid and functional. But there is no data. Here's the log produced by the workflow:

[2010-11-12 12:12:53.742] [I] DynamicWrapper (Instance) : [VcPerfEntityMetricCSV]-[http://class com.vmware.vim.vi4.PerfEntityMetricCSV|http://class com.vmware.vim.vi4.PerfEntityMetricCSV] -- VALUE : com.vmware.vim.vi4.PerfEntityMetricCSV@beb35d25
[2010-11-12 12:12:53.742] [I] undefined
[2010-11-12 12:12:53.742] [I] undefined
[2010-11-12 12:12:53.742] [I] undefined
[2010-11-12 12:12:53.742] [I] undefined

I also tried .format querySpec [0] = 'normal '; -same result.

Where is my fault? I'm on the right track?

Pls support me in obtaining data on performance, Thx.

-


Kind regards, Andreas Diemer

visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com/

SERVUS Andreas!

I think I got to the next step:

perfManager.queryPerf (...) returns a table, not the CSV values itself. Therefore, pop() data in the result table.

A change in your code that returns a large amount of data in my lab:

var CSVArr = VM.sdkConnection.perfManager.queryPerf (querySpec);  query PerformanceManager

System.log (CSVArr) ;// show if the type is OK

view properties

var CSV = CSVArr.pop ();

System.log (CSV.entity);

System.log (CSV.value);

System.log (CSV.sampleInfoCSV);

System.log (CSV.dynamicProperty);

But I do not know why the System.log (CSVArr) does not show the array as a type... (maybe because there is only one item!)

Edit: found the answer:

... - VALUE: com.vmware.vim.vi4.PerfEntityMetricCSV@229650a8 versus

..... VALUE: com.vmware.vim.vi4.PerfMetricSeriesCSV@5d7f26

"Once again learned!"

BTW: I found the idea with the table on the slide 59 of this presentation:

http://communities.VMware.com/servlet/JiveServlet/download/1371233-29453/vSphereAPI_PerfMonitoring.PDF

Hope this helps

See you soon,.

Joerg

PS: How can you add not formatted 'verbatim' sourcecode-style here in the forums?

Tags: VMware

Similar Questions

  • Impossible to get 'notes' of the virtual machine

    I tried to use a powershell script to get information from the virtual machine. I can get VMHost, VMname and GuestVersion using the script in the following, but failed to get the notes of the virtual machine. Anyone know why I can't get notes, please help me with that. Thank you in advance.

    report = @)
    foreach ($vmView in (Get-View - ViewType VirtualMachine))
    {
    $report += $vmView. Select-Object @{Name = "$vmhost"; Expression = {($vmView.Runtime.Host Get-View).} Name}},
    @{Name = "VMName"; Expression = {$_.} Name}},
    @{Name = 'Notes'; Expression = {$_.} Description}},

    @{Name = "GuestVersion"; {Expression = {$vmView.Guest.GuestFullName}}
    }
    $report | Sort-Object VMName-descending | Export-Csv "d:\vm_GuestVersion.csv" - NoTypeInformation

    There is no need to do it with the cmdlet Get-View.

    You can do

    $report = @()foreach ($vm in Get-VM){    $report += $vm | `        Select-Object @{Name="VMHost"; Expression={($_.Host).Name}},            @{Name="VMName"; Expression={$_.Name}},            @{Name="Notes"; Expression={$_.Description}},            @{Name="GuestVersion"; Expression={$_.Guest.OSFullName}}}$report | Sort-Object VMName -Descending | Export-Csv "d:\vm_GuestVersion.csv" -NoTypeInformation
    

    If you want to do with the cmdlet Get-View for any reason, you can do

    $report = @()
    foreach ($vmView in (Get-View -ViewType VirtualMachine))
    {
        $report += $vmView | `        Select-Object @{Name="VMHost"; Expression={(Get-View $vmView.Runtime.Host).Name}},
                @{Name="VMName"; Expression={$_.Name}},
                @{Name="Notes"; Expression={$_.Config.Annotation}},
                @{Name="GuestVersion"; Expression={$vmView.Guest.GuestFullName}}
    }
    $report | Sort-Object VMName -Descending | Export-Csv "d:\vm_GuestVersion.csv" -NoTypeInformation
    

    But note that as you need a view of the GET each time for the host name, performance will suffer.

  • How to connect sql database to esxi to save all data from the virtual machine

    How to connect sql database to esxi to save all data from the virtual machine

    Please provide steps

    In simple terms, you cannot connect ESXi to SQL. Connect a vCenter SQL (Windows only).

    If you want to save all the data that is contained in your virtual machines, I suggest a backup solution.

    Suhas

  • Script in time of latency list vm e/s and the data store the virtual machine is on

    Hello.  We have a vsphere 5.0 environment and we live a latency of IO heavy.  I'm looking for powercli script will get the latency of i/o for each virtual machine and get the data store name, to what it is now.  We will access our storage on optical fiber.  I'm trying to get a good overview of the latency of IO in a nice view in a csv file.  I found what could be a good basis to https://communities.vmware.com/thread/304827?start=0 & tstart = 0 , but I'm not sure how to get the name of the data store in the table and I think that it is written to the nfs in any case storage.  Thanks in advance for any info\advice!

    Try the next version, it includes the average latency time read/write for the virtual machine and PAHO are / s average for the virtual machine.

    Since the CSV has a row for each data store, the values for the virtual machine are repeated.

    I also added the host name

    $vmName = "VM*"
    
    $stat = "datastore.totalReadLatency.average","datastore.totalWriteLatency.average",  "datastore.numberReadAveraged.average","datastore.numberWriteAveraged.average"$entity = Get-VM -Name $vmName$start = (Get-Date).AddHours(-1)
    
    $dsTab = @{}Get-Datastore | Where {$_.Type -eq "VMFS"} | %{  $key = $_.ExtensionData.Info.Vmfs.Uuid  if(!$dsTab.ContainsKey($key)){    $dsTab.Add($key,$_.Name)  }  else{    "Datastore $($_.Name) with UUID $key already in hash table"  }}
    
    Get-Stat -Entity $entity -Stat $stat -Start $start |Group-Object -Property {$_.Entity.Name} | %{  $vmName = $_.Values[0]  $VMReadLatency = $_.Group |    where {$_.MetricId -eq "datastore.totalReadLatency.average"} |    Measure-Object -Property Value -Average |    Select -ExpandProperty Average  $VMWriteLatency = $_.Group |    where {$_.MetricId -eq "datastore.totalWriteLatency.average"} |    Measure-Object -Property Value -Average |    Select -ExpandProperty Average  $VMReadIOPSAverage = $_.Group |    where {$_.MetricId -eq "datastore.numberReadAveraged.average"} |    Measure-Object -Property Value -Average |    Select -ExpandProperty Average  $VMWriteIOPSAverage = $_.Group |    where {$_.MetricId -eq "datastore.numberWriteAveraged.average"} |    Measure-Object -Property Value -Average |    Select -ExpandProperty Average  $_.Group | Group-Object -Property Instance | %{    New-Object PSObject -Property @{      VM = $vmName      Host = $_.Group[0].Entity.Host.Name      Datastore = $dsTab[$($_.Values[0])]      Start = $start      DSReadLatencyAvg = [math]::Round(($_.Group |           where {$_.MetricId -eq "datastore.totalReadLatency.average"} |          Measure-Object -Property Value -Average |          Select -ExpandProperty Average),2)      DSWriteLatencyAvg = [math]::Round(($_.Group |           where {$_.MetricId -eq "datastore.totalWriteLatency.average"} |          Measure-Object -Property Value -Average |          Select -ExpandProperty Average),2)      VMReadLatencyAvg = [math]::Round($VMReadLatency,2)      VMWriteLatencyAvg = [math]::Round($VMWriteLatency,2)      VMReadIOPSAvg = [math]::Round($VMReadIOPSAverage,2)      VMWriteIOPSAvg = [math]::Round($VMWriteIOPSAverage,2)    }  }} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture
    
  • Details of the data of the virtual machine store

    Hi all

    Thank you is advanced.

    I'm trying to get the details of the virtual machine and its data store name, freespaceGB to n csv file. After excuting it I'm getting only the out put of the VM last on my list. Hope that I missed something in the addition of the output. Can someone please help.

    Add-PSSnapin VMware.VimAutomation.Core
    SE connect-VIServer 192.168.1.125

    #VMname.csv list of MV #.
    $vm = import-csv c:\scripts\vmname.csv
    {foreach ($line in $vm)
    Get-vm datastore - $line.name. Select-Object $line.name, name, FreeSpaceGB. Export Csv c:\scripts\ds.csv - NoTypeInformation
    }

    The result is that I'm looking is something like that.

    Virtal FreeSpace DS machine name

    VM1 DATA1 13 GB

    The virtual machine should be a calculated property, I've updated the code above.

    Give him another chance.

  • Is it possible to get use of the virtual machine Nic cards?

    Hi all

    I would like to know if there is possible to get the nic card (objectNetworkAdapterImpl ) send/receive rates of VM through the cmd-lets get-stat statistical data?

    Concerning

    Danny

    I decided to do a blog on it.

    See vNIC send and receive rates

  • Many "channels ATA" listed under "eject the material safely on the virtual machine.

    Hello world:

    Just create a new VM WIndows 7 Pro (clean install) as a guest in 10 Workstation running on a host windows system 7 Pro. When copying a large number of files over the network to a drive on data for the virtual machine, I noticed the noise of tale tell us to what looked like a point USB port being ejected and then reconnected. When I checked the icon 'Remove hardware safely' on the virtual machine there is a huge list indicating "Eject ATA channel 0" through channel 29? There don't seem to be valid items associated with these elements. There are also various other items that seem to be standard items for the virtual machine. I don't have it under other VM, although most of those that have been created in earlier versions of VMware Workstation and then upgraded to Workstation 10. Is this normal? Or something is running wild on this virtual machine?

    Any help would be greatly appreciated.

    Best regards, Dave Melnyk

    Hi Dave,.

    It is "normal" that the majority of our virtual PCI/PCIe and SATA devices are hot pluggable.  Another explanation (and workarounds, if you find it distracting) are in this thread: 10 Workstation: Windows 'Remove' Gone Wild

    We had a few questions about this lately, and we have had discussions on the question of whether we could eventually add a checkbox to control if these devices are default hot pluggable.

    In the meantime, feel free to ignore them or use the workarounds in the first thread I linked above.

    See you soon,.

    --

    Darius

  • How to set vm-description/notes and get the name of the data store, where the virtual machine

    Hello guys,.
    I have vCenter Orchestrator 4.1.1 build 733 installed and it works fine, but I need your help for the following two issues:
    (1) I want to put the description/notes of a virtual machine using a workflow. But I have not found any API useful to create this workflow (I don't want custom attributes, see attachment for details).

    (2) how can I get the name of the data store, where the virtual machine? I need this name for a workflow.
    I need your help.
    Thanks in advance!

    With regard to the notes of the VM, the following code (see enclosed package) can do this:

    var oldNotes = vm.summary.config.annotation;
    If (oldNotes == null) {oldNotes = ' ' ;}}
    System.log ("Notes of VM current:" + oldNotes);
    Now put the new notes:
    Start by creating a context
    Context of var = new VcVirtualMachineConfigSpec();
    Update the annotation with the new value property
    configSpec.annotation = notes;
    launch the task to reconfigure the virtual machine with the new context
    NOTE: This is sure to apply with a virtual machine under tension
    var task = vm.reconfigVM_Task (configSpec);

    And, in what concerns the VM information, take a look at the workflow of the library: \Library\vCenter\Virtual Machine management\Others\Extract virtual machine information

  • SRM 5.5 - vSphere replication - error: impossible to reverse the replication for the Virtual Machine. A snapshot operation cannot be performed

    Hi all, we have just run a test DR failover of a couple of virtual machines in our protected our failover site and all site swung perfectly, two virtual machines came online and all applications work well. However when we cam to r-eprotect machines virtual, we get some errors.

    One of the virtual machines seems to have lived the reprotect end process, it is still running, but has not moved to 89% for some time. The virtual machine has a couple of grand (a little less than 2 TB) VMDK. slow progress is just a consequence of the large VMDK?

    More worrisome is the virtual machine which don't reprotect at all. It generates an error whenever I click on the "Restore" button (error: impossible to reverse the replication for the Virtual Machine.) A snapshot operation can not be performed).


    Does anyone have any ideas as to the cause?

    Thanks in advance for any help.

    Andy

    Finally got to the bottom of this. The issue was that reprotect SRM work was trying to dispel any snapshots that were taken on the computer object virtual destination in VMWare, but could not clean snapshots.

    The reason why snapshots would not consolidate was because it was snapshots of temporary VEEAM who in fact any snapshot file listed in the VSAN data store. So when we looked through the browser data store, no snapshot file existed in the virtual computers folder. Trying a manual removal also failed.

    To fix this, we created a snapshot of the virtual machine in the original data center (note is the engine to the bottom of the virtual machine), this effect was to get rid of the 'fade' snapshot that was visible in the Snapshot Manager that VEEAM backup had left behind. Once this had disappeared, the reprotect back to DCA worked perfectly.

  • How to get the MAC address of the virtual machine on which vmware tool is not installed

    Hello

    In our project, we communicate to vCenter/ESX and details of virtual machines using the VI - Java 4.0.0 SDK APIs

    I use PropertyCollector for details.

    But in the following cases

    1. a virtual machine is poweredOff.

    2 VMware tool is not installed on the virtual machine.

    I am not able to get the mac using the PropertyColector address.

    To get the macaddress property I use after crossing spec:

    rootFolder (folder)-> childEntity (data center)-> hostFolder (Folder)-> childEntity (ComputerResource)

    -> host (Hostsystem)-> vm-> guest (GuestInfo)-> net (GuestNicInfo)-> macaddress (in Virtualmachine)

    I know the vSphere client uses the VI SDK to perform all operations, and I am able to see the macAddress of VirtualMachine in cases using vSphere client.

    Is any body please help me get the macaddress of VM in the two cases.

    Thank you

    Deepak

    Take a look at the dashboard feature of the virtual machine and specifically "VirtualEthernetCard": http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualEthernetCard.html

    When you assign a new vNIC to each virtual machine, a unique MAC address generated is given by default. If you still want to map the actual interface of the guestOS, then you would take a look at guestInfo as you may have noticed IF you have the VMware Tools. Although the default is whence the MAC address

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

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    Twitter: @lamw

    repository scripts vGhetto

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    VMware Code Central - Scripts/code samples for developers and administrators

    150 VMware developer

    If you find this information useful, please give points to "correct" or "useful".

  • Deployment of a virtual machine from a store of data with less space, but enough for the virtual machine

    I received this delicate task, and I can understand not just how to replace all parts.

    I need to create a script that will be smartly decided what data store to deploy a virtual computer.  We do not want to deploy in a data store that has the most space, we want to deploy to the data store that has the least space but can still account for the space for the (vm + 5%) and still leave 50 GB free on the lun after the move.

    Thus, for example, if the virtual machine is 40 GB, we want the script to select the data store that has a close to 90 GB available without being under.

    So my thought for this approach is:

    • Create the query to get all the relevant LUNS.  This excludes all the LUNS with the 'local' name in it and excludes all LUN owners (who have a slightly different naming convention then our general shared storage LUNS)
      • This piece, which I partially understood
        • Get-datastore. WHERE-object {($_.)} Name: corresponds to "PAR0 [1-4] _ [edp] * disk *")- and ($_.) "." Name - notmatch 'local')}
      • Now, I need to get all of their total size and free space.  Perhaps export this list to a CSV, however if I have to.
      • Create a variable that contains: the size of the total virtual machine to the virtual machine that is deployed before its deployment.
      • Deduct vm size against each data store size and pull in some way that that also close to 50 GB free on the data store and still facilitates the deployment of the vm.

    I have a few other scripts, I scrounged on the internet that I tried to restore... but I just don't calm not having all the pieces...

    • Get-Datastore. Where-Object {$_.} ParentFolder-match 'Internal'} ' | Select-Object - property data center, FreeSpaceMB, CapacityMB name, ' | Tri-objet-property FreeSpaceMB
    • Select-Object Name,@{n="CapacityGB";e={[math]::round (($_.)) {{(CapacityMB/1024))}}, @{n = "FreeSpaceGB"; e = {[math]: round (($_.))}} {{(FreeSpaceMB/1024))}}, @{n = "FreeSpacePercent"; e = {[math]: round (($_.))}} FreeSpaceMB / $_. {{(CapacityMB*100))}} | Sort-Object FreeSpaceGB

    Any help would be greatly appreciated!

    -Knotz

    Try something like this

    # Get all data warehouses

    $ds = get-Datastore. Where-Object {($_.)} Name: corresponds to "PAR0 [1-4] _ [edp] * disk *")- and ($_.) "." Name - notmatch 'local')} |

    Select-Object Name,

    @{n = "CapacityGB"; e = {[math]: round (($_.))}} {{(CapacityMB/1024))}}.

    @{n = "FreeSpaceGB"; e = {[math]: round (($_.))}} {{(FreeSpaceMB/1024))}}.

    @{n = "FreeSpacePercent"; e = {[math]: round (($_.))}} FreeSpaceMB / $_. {{(CapacityMB*100))}}

    {foreach ($vm in Get - VM)

    # Find possible candidates

    $candidates = $ds | where {($_.)} FreeSpaceGB - $vm. (UsedSpaceGB-50) - gt 0}

    # Find the best candidate

    $target = $candidates | Tri-objet-property FreeSpaceGB-descending | Select - 1 first

    Write-Output "VM $($vm.). Name) can go to $($target.) (Name) ".

    }

  • Delete the virtual machine to the specified date

    I'm trying to write a script to remove a virtual computer on a certain date.  Currently, I want people to add this in the name of the virtual machine "VMname_Delete-/ 1/1/14", I then search for the virtual computer with:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"}

    With that, I'm sure that the correct VM is selected, and I tested it with virtual machines to make sure.  Now comes the hardest part (at least for me), I want to take the date to which belongs the VM name, convert it to a DateTime and then compare it to the current date.  If they match, I want to remove the virtual machine.  I tried something in the sense of:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | foreach {$_ .name-split "-"}

    Which of course divide the table edge, and on tests, I had an output similar to:

    VM_Delete

    01/01/14

    Of course, now I don't know how to finish the rest.  I thought that the script would be something like:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    If (($_.name-split «-»)-[DateTime] - game (get-date-format ' MM/dd/yy'))

    {Remove-VM - VM $_ - DeletePermanently}

    }

    I don't see the logic in my head, but of course, I just can't write they way I think it should go.  Any help is appreciated.

    Perhaps you could do something in this direction

    $now = get-Date

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    $dt = [datetime]($_.) Name.Split('-') [1])

    If ($dt - lt $now) {}

    Remove-VM - VM $_ - DeletePermanently

    }

    }

    With the use of the index ([1]), we select the date part of the name of the virtual computer.

    Then we have "cast" the string into a DateTime object.

    Note that typeface could cause problems, depending on the culture settings you use.

    Worse, divide you the date on the character string ' / ' and then generate the DateTime object as follows

    $now = get-Date

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    $dummy, $year $day, $month = $_. Name.Split('-') [1]. Split('/')

    $dt = get-Date-day $day - month $month-year $year

    If ($dt - lt $now) {}

    Remove-VM - VM $_ - DeletePermanently

    }

    }

  • Get the IP of the virtual machine and MAC

    Hello

    I'm trying to get the IP of the virtual machine and the MAC one of my data centers.

    When I run that the following script two things happen:

    1. I don't see a vm in the output of the csv file.

    2. when I send the output to the quick PowrCLI I see only a mac and one IP address for virtual machines with network cards.

    Script

    ---------

    $MV = Get-Data Center $DC | Get-vmhost | Get - VM

    {foreach ($VM to $VMs)

    $VMx = get-view $VM.ID

    $HW = $VMx.guest.net

    foreach ($dev to $HW)

    {

    foreach ($ip in $dev.ipaddress)

    {

    $dev | Select

    @{Name = 'Name'; {Expression = {$vm.name}}.

    @{Name = 'IP address'; Expression is {$ip}},

    @{Name = 'MAC'; {Expression = {$dev.macaddress}} |

    Export-CSV VM - IP - Info.csv - NoTypeInfo

    }

    }

    }

    My console output, tested on a virtual machine with two external network cards and an internal interface "dummy".

    Name                               IP                                  MAC

    ----                                   --                                    ---

    VM1 192.168.1.1 00:50:56:xx:xx:xx

    VM1 192.168.2.1 00:50:56:xx:xx:xx

    VM1 192.x.x.xxx xx

    You see the addresses expected in summary using vSphere Client VM?

    Oh sorry, I forgot the PS 3.0 requirement.

    You can put all the entries in a table and export all at the end of the script.

    $out = @)
    $VMs = get-data center $DC | Get-vmhost | Get - VM
    {foreach ($VM to $VMs)
    $VMx = get-view $VM.ID
    $HW = $VMx.guest.net
    foreach ($dev to $HW)
    {
    foreach ($ip in $dev.ipaddress)
    {
    $out += $dev. Select @{Name = 'Name'; {Expression = {$vm.name}}, @{Name = 'IP address'; Expression = {$ip}}, @{Name = 'MAC'; {Expression = {$dev.macaddress}}
    }
    }
    }

    $out | Export-Csv - NoTypeInformation-Path ' VM - IP - Info.csv.

    Concerning

    Emanuel

  • Clone the virtual machine to the local data store

    Hi all

    I'm looking to automate a task daily (or almost) of my friends with a small script with powercli.

    I'm trying to "backup" or to clone a virtual machine, I work in a storage of one of our servers.

    The servers are managed by a 5.1 vCenter and the machine is on a shared storage.

    From time to time, I clean, stop the machine, remove all snapshots and clone the virtual machine to one of the local server as a backup storage. So I put together a small script which almost works. It works as long as the target data store is a shared storage, but not with a local storage.

    I get always an error that claims it can not access the local data store and is not a permissions problem...

    Given that I can accomplish this via the customer without problem I thought it is possible via powercli too, or I'm wrong?

    My Script up to now:

    # Variables
    $VC = "vc.domain.com" #vCenter Server
    $User = "domain\user" #User
    $Pass = 'test123' #User PW
    $VMName = 'scripttest' #VM
    $BackupSuffix = "backup" #Suffix to add the name of VM to mark this as a backup
    $VmHost = "esx2.domain.com".
    $Datastore = 'ESX2-LocalData' #Datastore
    $BackupFolder = 'Backup' #Folder the VM gets classified


    # Register cmdlets to VMware

    If (-not (Get-PSSnapin VMware.VimAutomation.Core - ErrorAction SilentlyContinue)) {}

    Add-PSSnapin VMware.VimAutomation.Core

    }


    # Connect to the server

    SE connect-ViServer $VC - user $User-password $Pass


    # Remove the old clone

    $OldBackups = get - VM | WHERE {$_.} {Name: corresponds to '$VMName - $BackupSuffix'}

    If ($OldBackups - don't "")

    {

    If ($OldBackups.Count - gt 1)

    {

    Write-Host "better check! "Found several results:

    Foreach ($VM to $OldBackups)

    {

    Write-Host $VM. Name

    }

    }

    on the other

    {

    Remove-VM - VM $OldBackups - DeleteFromDisk-confirm: $false

    }

    }


    # Clone VM

    $VMInfo = get - VM $VMName | Get-View

    $CloneSpec = new-Object Vmware.Vim.VirtualMachineCloneSpec

    $CloneSpec.Snapshot = $VMInfo.Snapshot.CurrentSnaphshot

    $CloneSpec.Location = new-Object Vmware.Vim.VirtualMachineRelocateSpec

    $CloneSpec.Location.Datastore = (get-Datastore-name $Datastore |) Get - View). MoRef

    $CloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse

    $CloneFolder = $VMInfo.Parent

    $CloneName = "$VMName - $BackupSuffix".

    $TaskCloneID = $VMInfo.CloneVM_Task ($CloneFolder, $CloneName, $CloneSpec)


    # Check if the task is completed


    $Check = $false

    While ($Check - eq $false)

    {

    $Tasks = get-job | Select State, id | Where {$_.} State - eq "Running" - and $_. State - eq "pending"}

    ForEach ($Task in $Tasks)

    {

    If ($Task.id - eq $TaskCloneID)

    {$Check = $false}

    on the other

    {$Check = $true}

    }

    Start-Sleep 10

    }

    # Move clone to the backup folder

    Move-VM - VM '$VMName - $BackupSuffix' - Destination $BackupFolder


    # Disconnect

    Disconnect-VIServer-confirm: $false

    Can you show us the complete error message you get?

    BTW, the clone step can be replaced by the New-VM cmdlet with the setting of the virtual machine.

  • Script to list all the warehouses of data in a cluster, the virtual machines on the data store and the host of the virtual machine is on

    We have warehouses of data which are seen by more than one cluster. I need a script that will display:

    all stores of data seen by a cluster

    the virtual machines on the data store

    the host of the virtual machine is on

    the cluster the host is in

    The output I want is

    name of the store of data, the VM name, host name, the name of the Cluster

    any help would be appreciated

    Pretty sure this will do what you need:

    $report = @()
    Foreach($cluster in Get-Cluster){
        $datastores = $cluster | Get-VMHost | Get-Datastore
        foreach($datastore in $datastores){
        $vms = $datastore | Get-VM
        If ($vms.count -ge 1){
            foreach($VM in $vms){
            $object = New-Object -TypeName PSObject -Property @{
                  Datastore = $datastore.Name
                  VM = $VM.Name
                  HostName = $VM.VMhost
                  Cluster = $cluster
                }
            $report += $object
            }
    
        }
        }
    }
    $report | Export-Csv C:\Temp\VMs.csv -NoTypeInformation -UseCulture
    

    If you only want to shared data warehouses you can then use

    $datastores = $cluster | Get-VMHost | Get-Datastore | Where {$_.Extensiondata.Summary.MultipleHostAccess -eq $True}
    

    Hope this helps

  • Method to move the virtual machines in the data store temporary so I can rebuild pool recommended NFS

    Our current data store is a mounting NFS on Nexenta (zfs), which has a pool, I need to rebuild (migration of raidz2 to mirror striped for performance). Initially, I was relying on the judgment of all virtual machines, create a new pool, copy (cp - r) of the Nexenta console all virtual machines to the new pool, recreating the pool mirror and then copy (cp - r) all the data back.

    I have seen several discussions on this topic and seems like the simplest method would be to use the feature to "Migrate" so that the virtual machines are not fragmented. However in some of my pre-test when I copy a virtual machine between the basins of the Nexenta console it appears (from the data store Explorer) to initially create the vmdk provisioned and then once completed it copy looks too thin.

    I hope that I can simply copy the Nexenta console, using the option "Migrate" in vCenter on each of my 40 MV looks like it would be * quite * tedious compared to the simple issuance of an order of 'cp - r' and leave all the copies of VMs (1.5 to) during the night and then adding them to each host.

    Does anyone have experience with this? Or maybe a way to generate scripts easily (?) the option "migrate" in vCenter?

    Thank you all!

    You can select multiple VMs in vCenter regularly using CTRL + click or shift + click and both migrate them as long as they have the same storage destination.  You can also schedule it as a task.    Add manually each computer virtual back in hand is not less painful than migrating individually, anyway.

Maybe you are looking for