A simple but difficult for me - Power off/on a list of virtual machines

I know that orders for food and on a virtual machine, but if I have a list of virtual machines in a csv format file, and I want to turn off (not free) and then power back them on, what is the best way to ensure that this is done?  Or even if I want to provide a list of virtual machines, how?

I thought about it, but has changed some things.  It works fine now.

Power off

$vc = Read-Host "Enter the name VC"

$cred = get-Credential

SE connect-VIServer $vc - Credential $cred

$file = "c:\temp\vmlist.txt".

$vms = get-Content $file

Get - VM $vms | WHERE-object {$_.} PowerState - eq "Receptor"} | Stop-VMGuest-confirm: $false | Out-Null

Disconnect-VIServer-confirm: $false

Power on

$vc = Read-Host "Enter the name VC"

$cred = get-Credential

SE connect-VIServer $vc - Credential $cred

$file = "c:\temp\vmlist.txt".

$vms = get-Content $file

Get - VM $vms | WHERE-object {$_.} PowerState - eq "PoweredOff"} | Start-VM-confirm: $false | Out-Null

Disconnect-VIServer-confirm: $false

Tags: VMware

Similar Questions

  • Simple, but difficult for me :(

    Hello
    I have a simple question here.
    I have A Table that has data saved in the following fields: ID, name, rank

    And my boss asks me to add a column more color to the Table with the following criteria

    If the Grade (x) is 1 < = < 3 x: give a RED color value
    If the Grade (x) 3 < = < 5 x: give a value of color ORANGE...


    How can I do an automatic update of time 1 so that I don't have to go through all the records in the Table and enter the color value manually...
    Please notify. Thank you

    It looks like you want smth like

    alter table tablea add (color varchar2(30))
    /
    
    update tablea
       set color =
             case
               when x >= 1
                and x < 3
               then
                 'RED'
               when x >= 3
                and x < 5
               then
                 'ORANGE'
             end
    /
    
  • I'm looking for a Script that can list all virtual machines with type of NIC E1000 via the output of the CSV file.

    Hi gurrus and LucD

    I'm looking for a Script that can list all virtual machines with type of NIC E1000 via the output of the CSV file.

    The script should search for information in a multiple Vcenter servers and multiple clusters and list all the VMs name, status (two powers on or off) with type card NETWORK Type E1000 only no other.

    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 |)) Where {Get-NetworkAdapter - VM $_______ | where {$_.}} Type - eq "e1000"}})) {}

    $report += $vm. Select @{N = "VM"; E={$_. Name}},

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

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

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

    }

    }

    }

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

  • Problem using cdromdisconnect.pl to check for the use of CD-ROM on the virtual machines

    I have a problem with this script, cdromdisconnect.pl and I was hoping someone could help me with it...

    When I run ' cdromdisconnect.pl - my.esx.host - host list op - my.vc.host - server passthroughauth ", I get a"Host not found my.esx.host." But when I run "datacenterlisting.pl - datacenter MyDC" there 'my.esx.host' very well. Am I missing something here? Why is the cdrom script not able to find hosts when other scripts have no problem?

    Any help would be appreciated.

    -monkeedu

    As far as I KNOW, there isn't a way to do a review on a MoRef, right on the property values.  You cannot, for example, match against a property value of the table.  You have to adapt your script logic.  Once you have your view of system host ($host), then you must use the vm ($host-> vm) property to get a list of Virtual Machines.

    You will probably need to change:

    my $host_moRef = $host->{mo_ref}{value};
    #######################################################################################
    #     Get all VMs that are currently running on that ESX Server
    #######################################################################################
    
    my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', filter => {'runtime.host' => $host_moRef});
    my $numDevices = 0;
    foreach my $vm_view (@$vm_views) {
    

    TO:

    #######################################################################################
    #     Get all VMs that are currently running on that ESX Server
    #######################################################################################
    
    my $numDevices = 0;
    my $vm_view;
    foreach (@{$host->vm}) {
         $vm_view = Vim::get_view( mo_ref => $_ );
    

    There are some optimizations I can suggest to speed it up, but its probably better to work first.

  • looking for a script to the list of virtual machines by datastore

    Someone at - it a script that lists each data store, then the virtual machines that are on it. Or maybe the list all virtual machines and data store or data warehouses is located in the virtual machine?

    Thank you

    This should do the trick for you.  In fact, it extends the computer object complete virtual with a property data store so you can still search the other aspects of the virtual machine.

    Get-Datastore. WHERE-object {$_.} {Name - like "DMX *"} | {ForEach-Object

    $dsname = $_. Name

    $_ | Get - VM | {ForEach-Object

    $($_ | Add - Member MemberType NoteProperty-name of store data-value $dsname - PassThru) | Select-object Name, host, Datastore

    }

    }

  • looking for a little help with 'ownership' of a virtual machine

    Power surge through my apartment while he was working on a school project, (I know I know, im getting a smooth paste to the top soon!)

    Now the virtual machine I was working on the guard telling me that the virtual machine is already is use, which is not, asking if I want to take owenship and and use it anway. by clicking on confirm a get error message saying "cannot open the file 'I:\Virtual Machines\Windows 7\Windows 7.vmdk': insufficient permission to access file.»

    If anyone has a solution for this would be great!

    go to the directory of the virtual machine

    Delete all directories whose name .lck
    You can also find files whose name .lck - they must be removed as well

  • Possible for the host to read the files on virtual machines?

    Is it possible for a host read files on virtual machines?

    If you can get information using vmrun command, then I think that vmware-cmd command will help to define the variables that can think inside the vmx file. As vmx file is inside ESX server only so that you can shut down the VM and edit the vmx file, then you can register to the virtual machine using the vmware-cmd command.

    Thank you

  • List of virtual machines in the data store but is not registered in the inventory

    I have a perl script that can list all the virtual machines in a datasore given by using the HostDatastoreBrowser object.

    However this only back vms who are registered. I want to be able to find images that have 'removed from the inventory' users but not destroyed on the data store.

    I even reach this may by using the HostDatastorBrowser? If this is not the case, how can I achieve my goal?

    Thank you

    Hello

    You can, but you may need to put the data in a different format. It is actually more a matter of perl a matter of VI Toolkit.

    You must create the appropriate list, then use the PERL map function to evaluate an expr on the entire list. Personally I just use a foreach example statement.

    Best regards
    Edward L. Haletky
    VMware communities user moderator
    ====
    Author of the book ' VMWare ESX Server in the enterprise: planning and securing virtualization servers, Copyright 2008 Pearson Education.
    Blue gears and SearchVMware Pro Articles
    Page top virtualization security links

  • Is it possible to power - off a virtual machine?

    Hello, I wonder if it is possible to power - off (no downtime) is a Virtual Machine with PowerCLI. I know cmdlet Shutdown-VMGuest but not a similar "Poweroff-VMGuest '...

    During the weekly virtual computer restarts, we see some test virtual machines by hanging the mode on the left (some Windows VM with gray screen without the mouse, etc...). Then I need strength and power - on those virtual machines because the case comments is not operational. Is it possible to make these Power-off with PowerCLtI?


    Thank you in advance.

    Best regards.

    You can use the Stop-VM cmdlet to turn off a virtual computer. If necessary you can even add the - Kill parameter to stop the virtual machines specified by ending their processes running on the ESX.

  • cannot not power off the virtual machine, but don't think the host it is running!

    I have two clusters VI3. An older cluster to 3.02 hosts and a new cluster with ESXi hosts. Level of current patch on ESXi hosts. New guests and old presenters sees the same storage, but I have additional storage which can see only the new virtual machine.

    Most of the migration to the new cluster went very well. A few questions. But a VM just GIVES me fits.

    After the failure of attempts to migrate the virtual machine to the new storage, I thought I just migrate the virtual machine to the new host and leave it on the old storage, for now, until we could find something later. VCenter events logs show that the migration has expired. However, the virtual machine appears in the new cluster and is no longer in the old cluster. Also, he turned on itself for some reason any. Turn off in Vcenter gives the error "the operation failed because another task is underway." Having the VM that I could put it off in before Vcenter, and no no unsure of how to use the RCLI for this, I have connected to the host directly mode "not supported" and has run vm-support - x to get the list of running virtual machines and their ID's so that I could kill him. However, the host does not include this virtual machine in the list of virtual machines. So I think a virtual computer that runs Virtual Center, but he thinks the host it runs on is unclear if I can't kill the process.

    Help?

    Have you tried to restart ESXi management officers, as well as the vc service is restarted?

    -KjB

  • The charge of the batteries of Smartphones blackBerry wise - Turn Off vs Full Power Off

    If I turn off my camera with Full Power Off, it will load more quickly than if I just use Turn Off?

    N ° but even if it does, the difference will be negligible.  I suggest to use the turn-off as opposed to full power in the distance, because some features, for example, alarm, still works with Turn Off but not with Full Power Off.

    I hope that helps you.

  • VM Power Off Date

    I created annotations for my virtual computers called LastPowerOn and LastPowerOff, I had planned to transfer the CreationDate from the entrance to the event log for 'VmPoweredOnEvent' and 'VmPoweredOffEvent' respectively.  Unfortunately, it seems that not all the events of power in newspapers are determined by the name of the event.  In vCenter, I view turn the events that do not appear as such.

    After trying my hand in this area and short coming, I borrowed a screenplay written by RvdNieuwendijk, which was designed to analyze the event logs VM for exactly this info.  This script also resulted in empty info for multiple servers.  So looking at the event log, this event seems not to appear the same as a manifestation of normal power:

    On DRS on the virtual machine
    Esx1.Jeff.com
    Info
    28/10/2011-13:57:25
    Power on virtual machine
    server100

    This is the code I use to test:

    Get-VIEvent -Entity $vm -MaxSamples 500 | Sort-Object -Property CreatedTime -Descending | Where-Object { $_.Gettype().Name -eq "VmPoweredOnEvent" } | Select-Object -First 1

    I fell the MaxSamples up to 500 to see if that was the problem.

    I can find the exact event, so I'm looking for:

    Template             : False
    Key                  : 11657
    ChainId              : 11651
    CreatedTime          : 10/28/2011 1:57:25 PM
    UserName             : 
    Datacenter           : VMware.Vim.DatacenterEventArgument
    ComputeResource      : VMware.Vim.ComputeResourceEventArgument
    Host                 : VMware.Vim.HostEventArgument
    Vm                   : VMware.Vim.VmEventArgument
    Ds                   : 
    Net                  : 
    Dvs                  : 
    FullFormattedMessage : DRS powered On server100 on esx1.jeff.com in
                           DataCenter1
    ChangeTag            : 
    DynamicType          : 
    DynamicProperty      :

    Any suggestions on where to go from here would be very useful.

    I thought to go to the data store and pulling the last modified date date the vmdk to establish a 'rough' power.

    Thank you

    Jeff

    Hi jeff,

    Thanks for your question. You found a serious flaw in my script from the thread to get a SSN last turning off date based on events of the virtual machine.

    And thanks to your suggestion, it was not difficult for me to change the line:

    Where-Object {$_.} GetType(). Name - eq "VmPoweredOnEvent"} | `

    in:

    Where-Object {$_.} GetType(). Name - eq "VmPoweredOnEvent" - or $_. GetType(). Name - eq "DrsVmPoweredOnEvent"} | `

    to solve your problem.

    Looking again my previous script, I found two other holes myself. You can probably say: "age comes with insight".

    The most serious is that the Get-VIEvent cmdlet returns only by the 100 default events. Maybe it's too small for some VM. So I added the MaxSamples parameter with value of 10000. Even if it is necessary to make the script executed well, it will make the script much slower.

    The other minor problem is that the previous script did the Sort-Object cmdlet in the pipeline before the Where-Object cmdlet. It is best to do the opposite. It is much faster because the Sort-Object cmdlet must sort the records less.

    Here's the new script will all changes:

    function Get-VMLastPoweredOffDate {
      param([Parameter(Mandatory=$true,ValueFromPipeline=$true)]
            [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] $vm)
      process {
        $Report = "" | Select-Object -Property Name,LastPoweredOffDate,UserName
        $Report.Name = $vm.Name
        $Event = Get-VIEvent -Entity $vm -MaxSamples 10000 | `
          Where-Object { $_.GetType().Name -eq "VmPoweredOffEvent" } | `
          Sort-Object -Property CreatedTime -Descending | `
          Select-Object -First 1
        $Report.LastPoweredOffDate = $Event.CreatedTime
        $Report.UserName = $Event.UserName
        $Report
      }
    }
    
    function Get-VMLastPoweredOnDate {
      param([Parameter(Mandatory=$true,ValueFromPipeline=$true)]
            [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] $vm)
    
      process {
        $Report = "" | Select-Object -Property Name,LastPoweredOnDate,UserName
        $Report.Name = $vm.Name
        $Event = Get-VIEvent -Entity $vm -MaxSamples 10000 | `
          Where-Object { $_.GetType().Name -eq "VmPoweredOnEvent" -or $_.GetType().Name -eq "DrsVmPoweredOnEvent"} | `
          Sort-Object -Property CreatedTime -Descending |`
          Select-Object -First 1
        $Report.LastPoweredOnDate = $Event.CreatedTime
        $Report.UserName = $Event.UserName
        $Report
      }
    }
    
    New-VIProperty -Name LastPoweredOffDate -ObjectType VirtualMachine -Value {(Get-VMLastPoweredOffDate -vm $Args[0]).LastPoweredOffDate} -Force
    New-VIProperty -Name LastPoweredOffUserName -ObjectType VirtualMachine -Value {(Get-VMLastPoweredOffDate -vm $Args[0]).UserName} -Force
    New-VIProperty -Name LastPoweredOnDate -ObjectType VirtualMachine -Value {(Get-VMLastPoweredOnDate -vm $Args[0]).LastPoweredOnDate} -Force
    New-VIProperty -Name LastPoweredOnUserName -ObjectType VirtualMachine -Value {(Get-VMLastPoweredOnDate -vm $Args[0]).UserName} -Force
    
    Get-VM | Select-Object -property Name,LastPoweredOnDate,LastPoweredOnUserName,LastPoweredOffDate,LastPoweredOffUserName
    

    Best regards, Robert

    Post edited by: RvdNieuwendijk added the - Force parameter to the commands of the new VIProperty.

  • Pavilion 15: Power off

    I have to use the shift with off switch key (on windows 8) to power the laptop off, if I use only only its turning off the display only, but is always cut power off button.

    Hello

    Try disabling the hybrid Windows 8 start - you can do the following.

    Right-click the battery icon, and select Power Options.  In the next window, click on "Choose what the power button" in the left pane.

    In the next window, click on "Change settings that are currently unavailable" (close), then Remove the check mark from the box against 'Turn on a quick start (recommended) '.  Click on the button Save the settings, and then close all open windows and check if the laptop will now be shut down properly.

    If this has fixed the problem, it may be useful by turning the quick start back on - sometimes simply remove and re-create the file will solve the problem.

    Kind regards

    DP - K

  • Simple disk alert for specific servers

    Hi all

    Can someone tell me how to alert of simple disk for specific virtual machines please? That is to say if Server X drive E:\ hits 20 GB free, send an e-mail.

    I tried to change the rule VMW Virtual Machine, use of logical disk , but I can't limit the scope to specific servers I want to follow. Very confusing.

    VFoglight v6.6.2 using.

    Thanks in advance.

    You can change the call to the scope to include only the specific virtual machines.

    You can test this concept in the Script Console, using the query line.  Don't forget that everything is case-sensitive.

    First, enter VMWVirtualMachine , and then select query.  You should see all your virtual machines

    Then, enter VMWVirtualMachine where name like '% ServerX' and you should get only back the corresponding VMs.  You can extend this to help where and not built.  for example VMWVirtualMachine where (name like name like '% ServerY' or 'ServerX %') once you're comfortable with that, we can take the step 2.  The '%' is a wildcard character, corresponding to a number any character.

    Now, let's take a look on your particular case, which is a little more complicated, because the name of the virtual machine is not directly part of the object VMWVirtualMachineLogicalDisk .

    We need to start with VMWVirtualMachineLogicalDisk as our base and then extend it.

    Still in Script Editor, enter VMWVirtualMachineLogicalDisk in the query line and select query.  You should see a large number of records of logical drive.  By selecting one of them and selecting the tab panel object below will show you some of the properties of this object.

    Then, enter VMWVirtualMachineLogicalDisk where name like '% C:' and select query.  You should see a small list, showing only C: drives.

    That's nice, but as the name property of the VMWVirtualMachineLogicalDisk object is the drive letter, not the name of the virtual machine, it does not help your case.

    The trick is to remember that these are objects, not rows in a table SQL.  And there's a handy article on the object called parentsmodel.  You can see by scrolling down through the selected properties of VMWVirtualMachineLogicalDisk , until you see relatives.  It is a link to the top of the object tree and can be used to select what need you.

    Enter VMWVirtualMachineLogicalDisk, where parents.name like "ServerX %", and you should see just logical drives for the selected virtual machine.  Again, you can build more complex criteria.  In addition, you should be aware that in certain types of objects, parents is not one, but a list of items (e.g. warehouses under the ESX hosts, where a data store can be a child of many ESX host.)  The query in this case would be built in a different way, to deal with several possible outcomes.

    OK, so now we are ready to make your new rule.  You NEVER want to change a standard rule, you should always copy rule, if necessary, the deactivation of the original.

    Copy rule VMW Virtual Machine, use of logical drive to a new rule and go to the tab of the rule definition.

    Under scope rule, you will see VMWVirtualMachineLogicalDisk in the largest area.  This can be entered in the menu dropdown just above him, but it can also be added to by typing directly into the larger area.

    Change the biggest box of VMWVirtualMachineLogicalDisk to VMWVirtualMachineLogicalDisk, where parents.name like '% ServerX' and test the scope of the rule with the little green check mark on the side.

    In green text, you shuold see that your scope has been changed to the desired list of virtual machines.

    Don't forget to press on save, very important

  • Virtual machines off the power during the response of isolation of riding

    We have 2 ESx 3.5 update 3 groups in our environment. Clusters have HA and response of isolation The Drs is configured from virtual machines under tension. During a network outage, on one of the hosts, all virtual machines were turned off. None of the virtual machines on other host turned off. Virtual machines had come back on the other cluster hosts once the network was up and VC was reachable.

    Prior to the maintenance of the network, due to a problem, this particular host was disconnected from the VC earlier. We were unable to connect to the server through the VI Client and restarted the service pass. Prior to the maintenance of the network, we identified that this single host was not related to performance on the VC Server data. Also some jobs started on the host would go to 100% but show never completed.

    My request is could the problem above caused virtual machines to restart despite the response of insulation parameter. Before the interview, I could find this host receiving the heart beats of VC server and other hosts in the cluster and VC showed no error associated with HA on the cluster or the particular host.

    We rebooted the host after the maintenance of the network and reconfigured HA on the cluster. Since then, it works fine. We had another interview to the network and we have had no problem with VM restarts.

    Looks like your ha agent may be dead as well as your connection between the host and VC.  There are several newspapers linked to HA, under/var/log/vmware/aam.  You can check to see if they provide additional insight as to why HA acted differently on a vs host others.

    -KjB

    VMware vExpert

    Don't forget to leave some points for messages useful/correct.

Maybe you are looking for