Find virtual machines on specific clusters

There are a number of clusters were trying to move away from virtual machine.  I'd like to understand what VM (and their associated properties as $_.) Folder) that can be found on these groups.   The following code takes a long time to run (he gets the number of old hosts rather quickly).

to connect-VIServer $VMServer
$VM2Move = @)

#Exclude virtual machines and hosts on the new groups
$AllOldHosts = get-vmhost-location $Location | where {$_ .parent-NotLike "newcluster01" - or $_ .parent-NotLike 'newcluster02'}
$OldHostTally = $AllOldHosts.count
Write-Host "is the number of hosts on old clusters: $OldHostTally.
#The of the $AllHosts that are desired properties are manufacturer, model, name, State, StorageInfo, Version
#The properties you want from virtual machines are host, name, PowerState, ProvisionedSpaceGB, record, Version

{Foreach ($OldHost to $AllOldHosts)
$VM = get-VMHost $OldHost | get - vm | Select name, folder, host, Powerstate, Version
$VM2Move += $VM
}

$VM2Move | Export Csv OldVM.csv - NoTypeInformation

When I get to the end of the pipeline 'select name, folder, host, Powerstate, Version', I get the following text:

Write-Host: error internal Win32 'not enough memory is available for procedures.
"SS this command" 0x8 occurred when writing memory console at the heart of the current output buffer
position of SLEEP. Contact the Microsoft Support Services.
To the chariot of C:\Documents and Settings\userID\My Documents\scripts\HostTally.ps1:54
: 11
+ Write-Host < < < < "$VM2Move".
+ CategoryInfo: WriteError: (:)) [Write-Host], HostException)
+ FullyQualifiedErrorId: WriteConsole, Microsoft.PowerShell.Commands.Write
HostCommand

I am still awating the output by using the statement select (still takes way too long).

How it should be written?  Any improvements would be appreciated.  It seems the only link between cluster and VM is through the host.  The virtual computer object has a property of the host and the VM-Host object has a Parent pointing to the cluster property.

Hello, JohnnyScript-

Welcome to the communities.

There are a few things to make it who can help speed up your code.

  • Since you already have objects VMHost Get-VMHost calling on line 4 of your code, you should not use Get-VMHost still once for each unique host (or any host)
  • There are a few variables that you need not, as the $VM2Move to the concatenation of data table and the $VM table of the selected objects
  • While we are cleaning things, we must not use Get-VMHost at all, really - Get-Cluster will suffice

So, with a bit of a re-write, you could generate data of OldVM.csv with something like:

## get all clusters not named the two given names&{Get-Cluster | ?{"newcluster01","newcluster02" -notcontains $_.Name} | %{    ## this cluster object, to be used later    $oThisCluster = $_    ## get the VMs in this cluster, and select a bit of info about each    Get-VM -Location $oThisCluster | Select Name,Folder,Host,PowerState,Version,@{n="ClusterName"; e={$oThisCluster.Name}}}} | Export-Csv c:\temp\OldVM.csv -NoTypeInformation -UseCulture

It ends by using Get-cluster and a Get - VM times once a cluster (vs using Get-VMHost once by the host and Get - VM host twice).  You should notice a fair speed increase.  If you really need the speed data, you could do even better with secret of most favorite people, Get-View.  We leave it for another year.

How does he for you?

Tags: VMware

Similar Questions

  • Using filters and Get - view to find virtual machines with a specific guest operating system.

    I have the following code snippet to find all virtual machines with the updated OS to ' Red Hat Enterprise Linux * "prompt. It does not work. If the filter is left out, I find myself with all virtual machines.

    The immediate question is the specs for the game ' Red Hat Enterprise Linux. " Originally from the "Performance Difference between GET - VM and GET-VIEW")

    http://www.batchworks.de/performance-difference-between-get-VM-and-get-view/ ).

    $ClusterFilter = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{“Name” = $ClusterName } | select -ExpandProperty MoRef

    $VirtualMachines = Get-View -ViewType VirtualMachine -Property Config -SearchRoot $ClusterFilter


    The biggest problem for me is to understand for Get-View filter. I was capable of a bit of insight to gleen from the URL below, but I think what Miss me is the reference (Microsoft) for what is happening to the right of the equal sign. What is the correct terminology for this type of query expression / where the syntax is 'left' = 'straight' and keywords such as "-match" are not allowed.

    http://purple-screen.com/?Cat=3

    VMware vSphere 5.1

    http://Wannemacher.us/?p=259

    Regular expressions with Windows PowerShell

    Right in the filter expression is an RegEx expression, please allow for characters before and after the word Linux.

    And the name of the OS is Config.GuestFullName.

    I corrected the entries more early as well.

    $ClusterName = "^MyCluster$"$ClusterFilter = get-view -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = $ClusterName } | select -ExpandProperty MoRefWrite-Host $ClusterFilter
    
    $VirtualMachinesNoFilter   = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter $VirtualMachinesWithFilter = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter -Filter @{"Config.GuestFullName"=".*Linux.*"}
    
  • Need a script to list all virtual machines on specific data warehouses

    I am trying to find a way to list all virtual computers on specific data warehouses. I use vSphere 5.1 and so far I got this:

    Get-Datastore. where {$_ .name - like ' * XXX * ""} | Get - VM | Select name, @{N = "Datastore"; {E = {Get-Datastore - VM $_}} | Sort name | FT - one

    This kind of work, but it would be perfect if I got this:

    -Group data store

    -Unique virtual machines (VMS to report only to the data store where the VMX)

    Any help appreciated.

    I relied on the fact that the first in the list would be the data store that holds the VMX, which apparently is a misconception.

    Try like this

    Get-Datastore-Name ' * xxx *' |

    Get - VM | Select the name,

    @{N = "Datastore"; E={$_. {{ExtensionData.Config.Files.VmPathName.split ('[]') [1]}} |

    Tri-objet-property data store name |

    Format-Table - AutoSize

  • find virtual machines connected to several groups of ports

    I am able to find a list of the virtual machines connected to a specific port quite easily.

    Get - VM | where {(Get-NetworkAdapter-VM $_ |)} (Select-expandProperty NetworkName) -eq "Network A"}

    I'd like to find computers virtual that are connected to multiple networks, except that I don't want not selected.

    I want a list of virtual computers that connect to the network but not connected to "Network A" and "Network B".

    The inverse of the one-liner above returns the same VM

    Get - VM | where {(Get-NetworkAdapter-VM $_ |)} (Select-expandProperty NetworkName) -don't "Network B"}


    Thank you

    Something like that maybe

    Get - VM | where {$nets = @(Get-NetworkAdapter-VM $_ | % {$_.NetworkName}); $nets. {Count - eq 1 - and $nets - contains "Network A"}

  • Virtual machines with oscillating clusters RDM

    People,

    We have two clusters at two knots with all nodes running ESX3.5 U1. Clusters have different CPU types that prevent from VMotion between clusters. All nodes are attached CF and share storage on an EMC CLARiiON CX3-80. Currently VMFS data warehouses, which are for most of the OS disks, are shared by all clusters, but the RDM (data readers) are presented specifically to one or other of the clusters. We are planning a major reorganization of our infrastructure which means Exchange effectively clusters for the majority of our virtual machines. Is there a more effective way of migration that detach the RDM, cold, migrate virtual machines and adding the back ROW on the other side?

    As you can tell my experience of internals VMware is currently quite limited, but I learn - as sometimes the hard way!

    Kind regards

    Paul Esson

    Hi Paul:

    Everyone here has some excellent suggestions. However, cold migrate a virtual machine that has the RDM will actually convert or clone the content of the ROW in a virtual disk. The original content of the RDM will be left intact, and the only way to avoid the conversion with a cold-migrate is to remove from the configuration of your virtual machine first ROW (as you mentioned). With the help of Storage Vmotion will only move the pointer of the RDM files and actually does nothing with the RDM themselves. You'd still have to place them in your storage array to another cluster.

    See the following article for a bit more detail:

    http://KB.VMware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1005241&sliceId=1&docTypeID=DT_KB_1_1&dialogID=42936094&StateID=0%200%2041484096

    -Dave

  • Find virtual machines in a range of IP addresses and name, IP and output Cluster

    Hello

    I am trying to create a script for the release of all the virtual machines that fall within a range of IP addresses and exit the VM name, IP address and the Virtual Cluster of machine is hosted in. I've got so far as to the release of the name of VM and IP, but can't seem to get the cluster to work. I can't find an expression for an attribute of Cluster in Get-View. Does anyone know how to complete it? Or maybe another way to go about this?

    Notice-EEG - ViewType VirtualMachine-filter @{"Guest.IpAddress"="10.10.10 *"} | Select Name,@{N="IP; E = {$_.guest.} Ip_address}}

    OUTPUT:

    Name                                                                                                 IP

    ----                                                                                                      --

    SERVER1                                                                                          10.10.10.1

    Thank you!

    Tony

    That foot kicks back an error for each virtual computer running trying to interview (below). I don't know, but you are able to use - property and - Id in the same line - filter?

    Get-view: all parameters can be resolved by using the specified named parameters.

    Online: 15 char: 13

    + View-EEG-Id $esx. VM-Name, property filter Guest.IPAddress @{'guest...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo: InvalidArgument: (:)) [Get-view], ParameterBindingException)

    + FullyQualifiedErrorId: AmbiguousParameterSet, VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

    Change what you have there to remove the - filter and add back to the place where the declaration did the trick. Runs without error, but still takes a minute or two to complete. But that's fine.

    foreach ($cluster in (Get-View - ViewType ClusterComputeResource-property name, host)) {}

    foreach ($esx in (Get-View-Id $cluster. Home - VM property)) {}

    if($ESX.) VM) {}

    Notice-EEG-Id $esx. VM-Name property, Guest.IPAddress | where {$_.guest.} {IpAddress-like ' 10.10.10 * "} |

    Select Name,@{N='Cluster'; E = {$cluster. Name}},@{N='IP'; E = {$_.guest.} Ip_address}}

    }

    }

    }

    If I wanted to filter by name of Vlan or VlanID would I be able to replace the Guest.IpAddress property for a related property of VLAN?

    Thank you very much for the help!

  • Find virtual machines with downtime more then a week

    Hello community,

    I'm looking for a command to find the virtual machines where the week then a longer time to stop-ist.

    I need this information to:

    Get - VM | Select-Object - property 'Name', 'Description', 'NumCPU', 'MemoryMB.

    I hope someone has an answer.

    Best wishes

    Jorn

    I think that the following script should produce those VM names.

    He begins by taking only the currently PoweredOff VMs.

    Then she collects all the virtual machines that have been turned off last week.

    And finally, it combines the 2 lists to find these virtual machines that have been turned off more than a week ago.

    I would like to know if it works for you.

    $vms = (Get-VM | where {$_.PowerState -eq "PoweredOff"}) | %{$_.Name}
    $events = Get-VIEvent -Start (Get-Date).AddDays(-7) | where{$_.FullFormattedMessage -like "Task: Power off*"}
    $lastweekVM = $events | %{$_.Vm.Name}
    $longer1week = $vms | where {!($lastweekVM -contains $_)}
    $longer1week
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Tool to find virtual machines with connected CD-ROM or a SQL query?

    What is a good way to find all the virtual machines that have the cd player or datastore ISO file attached host?

    RV tools will also work.  http://www.robware.NET

  • Best way to move virtual machines between two clusters: HP and UCS

    Hello

    We move the virtual machines in the cluster UCSChassis: 6 guests ESXi in a Cluster of HPChassis.

    I wonder how do it with minimum downtime.

    Thanks for your help,

    If you have shared storage - expose the storahe where virtual machines are stored to both sets of guests - and the hosts are ocmpatible you can vmotion - or at least - to stop the mover VM's from the environment of the UCS and add it to the HP environment.

    If you can't share the storage you - you can use VMwate Standalone converter and V2V the VMs-

  • Find virtual machines without a VC

    Hey all

    Wondering if you could please help?

    I recently lost my VC (which is a virtual machine) and then realized I didn't host it was to get running. Therefore, to ensure that this does not happen again I tried to create a script (a base to it) just to tell me what hosting the "CV" is on a problem occurred again. The problem is the script keeps looping and the slightest mistake when trying to connect to a host. The script is as below and any help would be greatly appreciated.

    Munster


    $rootcred = get-Credential

    $esxservers = get-Content c:\scripts\prodservers.txt
    $vm = Read-Host "enter the name of the VM:

    foreach ($esx to $esxservers)
    {
    SE connect-VIServer-Server $esx - cred $rootcred
    (Get - VM $vm)
    {if ($VM)}
    Write-Host $vm"is on:"$esx - ForegroundColor white. "
    }
    else {}
    Write-Host $vm"is NOT on:"$esx - ForegroundColor Green
    }
    Disconnect-VIServer-Server $esx - confirm: $false
    }

    Hello

    I had the same problem as you and I solved it with the help of host DRS Group Manager. So vCenter Server and the database server is still running on a dedicated host.

    I've published a how-to post on my blog http://www.vmworld.net/?p=1240, but it is written in German - voicie so a little explanation:

    .) make a VMS DRS group - member vCenter Server + Server DB

    .) make a host group of the DRS - Member ESXHost where you will the vc to run

    .) make a rule of Virtual Machines to the host where 'VM Group'-> 'should run on hosts in the group'-> host group

    Important: use "should run on the hosts in group" and NOT «must run...» "because he's so HA and DRS know.

    So every time will know where your CV is running...

    Concerning

    Andi

  • Find virtual machines with disks of 'thin '.

    Hello

    I'm looking for a script that locates the virtual machines with disks of 'thin' and retrieves information about the provisioned size and "used" actual size and output to a CSV file.

    Thank you in advance!

    This gives you a report on virtual machines with thin discs and the capacity of your hard disk.

    Validated clerk/no values are available only through VM by the data store, I'm afraid, not by the hard drive.

    $report = foreach($vm in Get-VM){    $vm.Harddisks | where {$_.StorageFormat -eq "Thin"} |    Select @{N="VM";E={$vm.Name}},@{N="Harddisk";E={$_.Name}},    @{N="ProvisionedGB";E={[math]::Round($_.CapacityKB/1MB,1)}}}$report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
    
  • Script to find virtual machines on data warehouses that begin by...

    I'm looking for a script that will list all VM on specific data with the initial T1SDX1 letters warehouses. I tried to use a certain liners, I found, but they do not seem to work. Here's what I'm not, but it does not list the VM.

    Get-Cluster "Test Cluster" | Get-vm |?{($_.extensiondata.config.datastoreurl|%{$_.name}) -like "T1SDX1"}| Export-Csv "H:\Excel_Reports\vms_on_whatDS.csv"
    

    I tried to use the same command - and -contains the command. Both show no results. I tried a single line, I found here, but it signals a TON of data I don't need and does not even get the info, I need.

    Get-Cluster "your_cluster"|Get-vm |?{($_.extensiondata.config.datastoreurl|%{$_.name}) -match "^T"}
    

    In fact, I found an old script I used who shot all s VM on all data warehouses. It works, I'll just filter across the worksheet.

    Here's the script if anyone cares or she wants:

    $Today = (Get-Date -Format "yyyyMMdd-HH.mm")
    $vcenter = $defaultVIServers
    $report = Get-Datacenter | Get-Datastore | Foreach-Object {
        $ds = $_.Name
        $_ | Get-VM | Select-Object Name,@{n='DataStore';e={$ds}} |
        }
    $report | Export-Csv "H:\Excel_Reports\DS.stats.$vcenter.$today.csv" -NoTypeInformation -UseCulture
    
  • Virtual machine creation dates (birthdays)

    I worked on a little dashboard that allows you to find virtual machines created in view of a specific range of dates.  It takes all virtual machines, located between a series of dates and shows on a table.  It looks like at any time, but I'm curious to know if others would filter down again by vCenter/Cluster etc...

    Thoughts?

    This is the cartridge for you to take a look at.

    http://en.community.Dell.com/TechCenter/virtualization/infrastructure/w/fog-virt-wiki/5731.Community-cartridge-VM-creation-date

  • 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".

  • Judgment of virtual machines on a host in a certain type of order

    I'm writing a stop in perl (new to perl script

    programming) my edit the ghettoshudown script. What it does so far

    stop or suspend all virtual machines

    on a host, but it does not cut the

    down in a specific order (which is the ultimate goal). Is there anyway to do

    This in perl, possibly using an external file. Any help would be

    greatly appreciated.

    I've attached what I have so far.

    Oh, can't believe I missed it.  Sorry, stupid mistake on my side.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use VMware::VIRuntime;
    
    my %opts = (
         vmfile => {
              type => "-s",
              variable => "VMFILE",
              help => "Path to file containing list of virtual machines, one per line, for ordered shutdown",
              required => 1,
         },
    
    );
    
    Opts::add_options(%opts);
    Opts::parse;
    Opts::validate();
    
    my ($vm_view, $vm_name, @vm_list, $vm_file);
    
    $vm_file = Opts::get_option('vmfile');
    open (VMFILE, $vm_file) or die "Failed to open file, '$vm_file'";
    @vm_list = ;
    close(VMFILE);
    
    Util::connect();
    
    foreach $vm_name ( @vm_list ) {
         chomp ($vm_name);
    
         $vm_view = Vim::find_entity_view(
              view_type => "VirtualMachine",
              filter => { 'name' => $vm_name },
              properties => \[ 'name' ], # remove backslash before '[', forum mangles this line without it.
         );
    
         unless( defined $vm_view ) {
              warn "Unable to find virtual machine, '$vm_name'";
              next;
         }
    
         eval {
              $vm_view->PowerOffVM_Task();
         };
    
         if ($@) {
              print "Virtual Machine PowerOffVM_Task Error for $vm_name:\n$@ . "\n";
         }
    
    }
    

    Notice the line filter-online {'name'-online $vm_name}, for changes.

Maybe you are looking for

  • Image treatment find cirle

    Hello I created an application to find a circle to my workspace. The application is not so stable. I used the following modules in the order in a sequence structure flat (I'll delete it finally): IMAQ excerpt 2-> IMAQ ExtractSingleColorPlane-> IMAQ r

  • Problem with windows xp, commissioning

    When I turn on my windows xp-based computer does not start correctly. A black screen is telling me to hit ctrl alt delete at startup. Then when I do a blue screen comes up saying windows has encountered a problem to check any newly installed hardware

  • Unable to print - tried several troubleshooting

    Continue to be "Document cannot print" using hp pavilion dv7 (Vista) and officejet pro 8500 A909g Printer wireless network Test report: no problems found. All Diagnostics passed. HP Print & Scan Doctor: 'fixed queue error' - still cant print; Get the

  • Problems after update 10.4.1.b.0.101

    Upgrade to version above this morning and since then my microphone speaker, headphones, music everything has stopped working... Has anyone faced this problem? How can I restore? Solution? I use Xperia zr and upgrade has completed without any problem

  • INTELL CORP. ADDAPTER WDD1.1 & WDD1.2 & HD GRAPHICS GRAPHICS WILL NOT BE INSTALLED. HAS NO SENCE 8/15?

    DISPLAYS THE CODE OF ERROR 80070103. HAVE A HP DESK TOP RUIN WIN 7 Help, please.