Run a Windows command on all virtual machines

Using PowerCLI, is it possible to run a Windows command on all virtual machines?  I would like to hiberbation disabled on all my servers as it is unnecessary and take up disk space.  Running powercfg-h off will do, but I really want to do it on all 200 of my VM.

I can't seem to find the option in group policy, so I was hoping that this could be an option.

The above posts are excellent resolutions. Here is another possible approach.

You can do this with a Powershell script. Something like this should work:

  1. The list of virtual machines:

SE connect-ViServer here VCenter server name

$vms = get - VM

  1. If you have installed Powershell and PSRemoting enabled on each virtual machine, run the following:

$vms | foreach-object {Invoke-Command - ComputerName $_.} Name - ScriptBlock {powercfg - h}

  1. If you have not installed Powershell and PSRemoting on each virtual machine, use WMI:

foreach ($vm to $vms)

{

$vmName = $vm. Name

(\[WMIClass\] ")
(' $vmName\ROOT\CIMV2: Win32_Process "). Create ("cmd /c powercfg - h)

}

You should probably use the WMI method since it is unlikely that all of your virtual machines have Powershell installed and configured for remote access.

Tags: VMware

Similar Questions

  • Run a remote command on a virtual machine

    I have a remote application that generated virtual machines by request. After that each machine is generated and custom, I need to run a command-line on this machine (machine all have Windows OS installed) of the application itself.

    Is there a way to do it through the java/vsphere API?  (The machine is running on)

    Thank you

    the vSphere API does not provide capabilities to execute commands within the guestOS which is what uses the SDK for Java (VMware Tech Preview of Java SDK) and VI (Version of Steve Jin).

    However, VMware has an another API that is available for the management of comments called VIX API. This API allows you to perform operations within the guest, transfer files to/from host, etc. There is even a project open source similar to that of VI Java API called Toolkit Java VIX you could look in - http://sourceforge.net/projects/vixjava/

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

    William Lam

    VMware vExpert 2009,2010

    VMware scripts and resources at: http://www.virtuallyghetto.com/

    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

    VMware developer community

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

  • GUI: how to run the same command on multiple virtual machines at the same time?

    Hello

    Suppose we have several operations on multiple virtual machines (for example as updated virtual hardware, install vmtools - but it could be something else of course...).

    I would avoid clicking on each virtual machine (especially when we have hundreds of different groups).  It is possible to select sort

    (they are not side by side) and perform on a particular operation on all selected both?

    Hello

    If you use vCenter 5.1 + you can also try to use marking and assign tags on the items in the inventory.

    VSphere 5.5 Documentation Center - apply a label to an object

    Search for items by this tag.

    If you want to use PowerCLI 5.5, you can also search the inventory by this tag.

    Get-VM-Tag which lists all the virtual machines with which

    Here are some links for getting started with vSphere PowerCLI

    Back to Basics: part 1 - installation PowerCLI | VMware PowerCLI Blog - Articles from VMware

    vSphere PowerCLI Documentation

  • Access to the network in all virtual machines lost after that put 8.1 to level.

    Today, I upgraded my host computer to Windows 64-bit Pro 8.1. I did the upgrade through the Windows store. There are no errors or problems during the upgrade.

    However: The host machine equipped with a Qualcomm E2200 network adapter, and it runs the 'Killer' Network Manager software called at startup. After the 8.1 update, when the machine did its last restart, Qualcomm Network Manager opened with a message that the LSP has not mapped correctly. I clicked 'YES' to remap it. Probably a stupid move on my part.

    Thereafter, I lost all network connectivity in all my virtual machines. I have virtual machines for Windows 8, Windows 8.1 RTM (not the preview) and Ubuntu 12.04 LTS. ALL of them have lost the network.

    The host computer has no network problem and works well after the upgrade.

    Any ideas or suggestions to reset network connections in virtual machines?

    All virtual machines are set to use NAT.

    Oh I have to say also that the host computer is running VMware Workstation 10 and everything was fine and dandy, has never had problems at all until this upgrade/LSP remap thing. I have install VMware Tools in the VM of Windows 8.1, with no effect at all.

    Thank you.

    -J

    Two things, I'll try:

    1. go in the virtual network editor and restore settings. The culprit is probably the VMNet to NAT configuration.

    2. If this does not work, it seems that the virtual card for NAT does not somehow. The simplest workaround is to uninstall and reinstall the workstation.

  • Is no vmdk file, but the script says, all virtual machines backed up Ok!

    Hello everyone;

    Please excuse any lack of details because this is the first time that I write. I've scoured internet for days now trying to find no matter how much detail that could help me solve the problem. I'm new in the world of script ESXi and ghettoVCB.

    My intention is to run several tasks on a schedule. Each type of backup (quarterly, monthly, weekly, daily and multiple) runs at a specific time. The planning section works very well.

    I'm hoping to solve this urgent backup, I should be able to solve reboot.

    Here is the command I use:

    /vmfs/volumes/datastore1/ghettoVCB.sh w /tmp/ghettoVCB-work.multiple f/vmfs/volumes/datastore1/vmlist-Multiple g/vmfs/volumes/datastore1/vmconfig-DataSet1-multiple-l /vmfs/volumes/datastore1/ghettoVCB_logs/ghettoVCB.Multiple_Backup.log

    vmconfig-DataSet1-multiple contains:

    # Multiple backups - rotation County 6

    #

    VM_BACKUP_VOLUME = / vmfs/volumes/Vault2-DataSet1/URANUS/Multiple

    DISK_BACKUP_FORMAT = thin

    VM_BACKUP_ROTATION_COUNT = 6

    POWER_VM_DOWN_BEFORE_BACKUP = 0

    ENABLE_HARD_POWER_OFF = 0

    ITER_TO_WAIT_SHUTDOWN = 4

    POWER_DOWN_TIMEOUT = 5

    SNAPSHOT_TIMEOUT = 15

    ENABLE_COMPRESSION = 0

    VM_SNAPSHOT_MEMORY = 0

    VM_SNAPSHOT_QUIESCE = 0

    VMDK_FILES_TO_BACKUP =

    Vmlist-multiple contains 1 server is listed:

    # List all virtual machines that are backed up several times a day

    HEAT

    The log indicates that the backup was successful - but it has not been the case. Backup size should be approximately 8 GB. However, when you look at the output folder, only the following files are here:


    HEAT.vmx

    STATUS.ok

    Question is now - where are the vmdk files that should be present?

    Output (-d debug) can be found here: http://pastebin.com/hMGphTL3

    So, here is what I observed:

    When you run the script, the snapshot only takes a few seconds to create and delete then. I'm seeing happens on the list of the tasks of vSphere Rencent (screenshot attached).

    If I create a snapshot manually - it will take much more time to create and delete a snapshot. The difference here is 6 minutes, and 4 seconds using the script create a snapshot manually.

    So my presumption is that he is not actually create the snapshot, although vSphere said it is being created. So why is it the case?

    Help, please.

    ADDENDUM:

    If I run the following:

    ./ghettoVCB.sh m HEAT

    The backup is successful.

    Your said he clearly did not config file to back up all files hard.

    VMDK_FILES_TO_BACKUP =

    I expect to see something like this if you want all the hard files

    VMDK_FILES_TO_BACKUP = "all".

  • Windows on VM - says my copy of Windows 7 on the virtual machine is not authentic

    I have the Virtual Machine on a Mac and am running Windows 7 on the virtual machine.  I get a message that my copy of windows is not genuine, so, how do I get a product key.
    I get a message from Microsoft that this copy of Windows is not supported.  If I need to buy Windows overall, how can I download it to VM?

    You can purchase a license for the edition you installed and change the key and activate it on the Internet.

    http://www.Microsoft.com/Windows/buy/default.aspx

    http://Windows.Microsoft.com/en-us/Windows7/get-a-new-Windows-product-key

    Click Start, right click on computer

    Click on properties

    Scroll down to the Windows Activation

    Click on the link "change product key".

    Enter the product key and click next to activate via the Internet.

  • vCenter shows all virtual machines and the host is disconnected

    Hello

    I have a two nodes in the cluster ESXi6 U2 (recently updated to 5.5) running on hp dl380p gen8. For some reason all the virtual machines are running on host A (HA and DRS are enabled).  vCenter shows all virtual machines and host A is disconnected. Cannot connect to A host using vSphere client or web client. Cannot vMotion the VMs. Impossible to activate SSH. Connection DCUI works very well. Cannot perform any action VM

    All virtual machines are in place are running at this point. I don't want to restart the virtual machines. Can you help me please?

    Thank you

    AJ

    Frozen screen DCUI came back to life. The active SSH access, killed the running process. The host of running backs.

    See you soon,.

    AJ

  • ESXi 4.1 upgrade to ESXi 5.5 while all virtual machines and data warehouses

    We have two servers ESXi 4.1.0 348481 (Essentials) and we need to upgrade to ESXi 5.5 for support of Windows Server R2 2012. We intend to use the interactive upgrade. We want to ensure that the virtual machine is preserved. More precisely VMFarm001 where ESXi is installed in the same data store as VMServer1. VMServer1 is our largest server and cannot be migrated to another data store easily because we are not allowed for vMotion.

    The following layout

    VMFarm001

    Dell PowerEdge R710

    Data store:

    Storage1 - 1.36 TB

    VMServer1 - MS Server 2003

    Install ESXi

    Storage2 - 1.82 TB

    VMServer2 - MS Server 2008 R2

    VMServer3 - MS Server 2008 R2

    VMFarm002

    HP ProLiant ML350 G5

    Data store:

    Storage1 - 95GB

    Install ESXi

    ISOs

    Storage2 - 1.82 TB

    VMServer4 - MS Server 2008 R2

    VMServer5 - MS Server 2008 R2

    I have a feeling I'm worried for nothing given that option during the ESXi upgrade and keep the VMFS datastore.

    Thank you

    Yes, that's correct.

    I recently finished the upgrade of lots of stand-alone hosts ESXi 4.1 (with local storage only) to 5.1 and all were successful. The same process applies to 5.5, so you shouldn't have a problem with preservation of VMFS data warehouses (and all virtual machines).

  • Gwetting a list of all virtual machines and used space


    I apologize for my very basic question.

    I need to make a file (better if an Excel file) with a list of all virtual machines in a simple 5.x vSphere infrastructure including 2 VMare ESXi 5.x servers and the disk space used (allocated, used) of each virtual computer.

    The easiest way seems to list the virtual machines from the vSphere client and export the list as a .xls file.

    It seems simple, but when I look at the file I see a lot of missing VMs or a large number of missing values for several virtual machines (just the Runts).

    Is this a problem with my vSphere client?

    I tried to create a PowerCli script using the "Get - VM|" Select-object Name"command, but my limited skills will let me extract the value of the used space.»

    Can someone please provide a sample of PowerCli I can just copy and use?

    Is there another way to get the information I need?

    Concerning

    Marius

    .

    Not knowing that if you have configured a cluster or just stand-alone hosts, here is one simple line...

    Get-VMHost-name | get - vm | select name, usedspaceGB

    From there, you can make formatting, get total usage etc.

  • The list of all virtual machines with more than 2 virtual disks

    Hello.

    I want to list all virtual machines in a data center vCenter, who got more than 2 virtual disks. Here's the workflow, I am working on that:

    1 get the view of data center

    2. get the Cluster Data Center view like the 'begine_entity '.

    3. for each view cluster overview the VirtualMachine bit cluster seen as 'begin_entity '.

    4. for each VM view, this information: VirtualMachine-> config-> hardware-> device of

    Above information is a table.

    I need help in order to extract information from this table disk, then run an if condition where the VM who got more than 2 discs should print.

    Could help you. I wrote the script to the point 4. just need advice for the posterior.

    Thank you.

    You can try one of the following values-

    1 If ($vm-> {'summary.config.numVirtualDisks'} > 2) {...}

    2 $diskCnt = grep {$_-> isa ('VirtualDisk')} @{$vm-> {'config.hardware.device'}};

    The above assumes that you've got your $vm with a filter property as follows:

    $vms = Vim::find_entity_views (view_type-online 'VirtualMachine'), the properties-online ['summary.config.numVirtualDisks', 'name', 'config.hardware.device'];

    my $vm foreach (@{$vms}) {}

    ...

    }

  • Setting Options such as Hotplug for all virtual machines

    Hello!

    I have about 5 esxi hosts 5 and about 50 virtual machines

    Unfortunately I forgot to select some options like activate the plug-in memory and cpu hot

    I have 2 questions

    1 can I do this without turning off the machine

    2. How do I make a few options like this (or for example another option as vmtools update during the feeding cycle) for all virtual machines in my environment

    It's too much time to go to all virtual machines and turn them off and turn on these options

    Thank you very much

    These features must be enabled before the virtual machine is running.  So, you will need to turn them off and then use something like powercli to enable the features and turn them back on.

    Here is an example on how to do it with powercli: http://ict-freak.nl/2009/10/05/powercli-enabledisable-the-vm-hot-add-features/

    -KjB

  • How can I pay for the reservation of memory on all virtual machines to "0"?

    I am trying to write a script that will pay for the reservation of memory on all virtual machines that are invited in a cluster to '0 '.  We have book too much memory, and this setting should allow VMWare facilities manage reserves memory for me.  I have hundreds of virtual machines to update, so I can't do it by hand.  I hope that it is possible via the CLI.

    Can someone help me with this please?

    Matt example work certainly, and I'm sure that he was going to follow up with something similar to this after having confirmed if it worked or not because it is much more serious on the optimization of code for speed, but I'll (try to) save the effort. To test its extract on a cluster of 45 VMS, it took more than four minutes to complete.  The excerpt below took about 25 seconds.  The difference is of course to use the cmdlet "Get-View" and that it can run asynchronously so (it begins a vCenter task and immediately passes the following).  Of course, this will also put more of a strain to your vCenter server, so keep that in mind.

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $spec.memoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo
    $spec.memoryAllocation.Reservation = 0
    Get-Cluster "YOUR_CLUSTER" | Get-VM | Get-View -Property Config.MemoryAllocation | %{$_.ReconfigVM_Task($spec)}
    
  • All virtual machines are dead

    Hi, I discovered today that all virtual machines on my ESXi 4 has been arrested.  There are balls I can check what happened?  4 virtual machines are all CentOS 5.5 64-bit and very lightly loaded (IE TOP shows 0.1 for loading).  There is no more validation of CPU or memory.

    You can... How to do this depends on your configuration... For example, if you use vCenter or not. If this isn't the case, then connect to the host, go to the tab "Configuration", under the heading 'Software', ' Virtual Machine Startup/Shutdown ' select and then click on the 'Properties' link (top right of this window)... This is where you can select the VM power on with the host country, what order they put under tension, or if they "Manual start" value when the host starts.

    If you do the settings on the host computer, vCenter will extract these settings in the configuration... I would suggest testing to confirm that the auto-start settings stick when you vMotion a computer virtual to another host (if you have more than one host) or not.

    Network administrator

    VMware VCP4

    Review the allocation of points for "useful" or "right" answers.

  • Start all virtual machines

    Hello

    A couple of weeks, I installed Vmware server 2.0 on Ubuntu 8.04 server, I must say that it works perfectly, I encounter any problem yet. At this point, I am trying to automate some processes such as backup and start and stop virtual machines.

    The thing is for the moment we have 4 virtual machines and im starting those manually now (1 by 1) using the vmrun command, now my question is, is anyway to start all virtual machines at the same time? I tried many things and I can't make it work, some help would be really appreciated.

    Thanks in advance and best wishes,

    Stone.

    OK - enter you requirement exactly, in my defense.

    I posted earlier, a shell script to the server 2.0 beta forum, which found all the *.vmx scripts, and then made a "suspend" their needs so very easy to change it to do a 'departure' instead.

    See the 'vmware - suspend' script in this post:

    http://communities.VMware.com/message/1036371

    Post edited by: guyrleech

  • I installed windows 2000 on a virtual machine on a different computer than windows xp.

    I installed Windows 2000 on a virtual machine to another Windows XP computer. I'm under the it on my new computer with Windows xp. I get the icon in the bar lower right spots showing an internet connection but no Internet Explorer or Firefox will have access to the internet? In the Device Manager on Windows 2000, it shows a map network intel but on the computer Windows Xp host computer and in the "settings" on the Windows 2000 installation it shows my Realtek card. Is the adapter intel a virtual card? I tried to uninstall the Intel card and then install the Realtek but Windows 2000 installation does not see the Realtek card. On a restart, the Intel card is reinstalled.
    Am I a fight lost because I did the first Windows 2000 install on another computer in Windows XP?

    Hi MrRobHill1965,

    Given that the problem is related to the virtual machine, I suggest that you post your question on the forums of Virtual PC listed below.

    Windows Virtual PC and XP Mode Forum

Maybe you are looking for