Script to change vmx file

The following script provided by vmware in KB2092807 is stuck in a loop.  After connecting to the viserver, I'll run the following:

ForEach ($vm in (Get - VM)) {}

$vmv = get - VM $vm | Get-View

$name = $vmv. Name

$guestid = $vmv. Summary.Config.GuestId

$state = $vmv. Summary.Runtime.PowerState

$vmx = new-Object VMware.Vim.VirtualMachineConfigSpec

$vmx.extraConfig += new-Object VMware.Vim.OptionValue

$vmx.extraConfig [0] .key = "monitor_control.enable_softResetClearTSC."

$vmx.extraConfig [0] .value = 'TRUE '.

If ($guestid - like ' windows8 * Guest ') {}

($vmv). ReconfigVM_Task ($vmx)

If ($state - eq "receptor") {}

$vmv. MigrateVM_Task ($null, $_.) Runtime.Host, 'highPriority', $null)

}

}

}



But the above script get into a loop and vcenter taskbar will show «Reconfigure the machine virtual vmname finished...» «and «Migrate machine virtual vmname finished...» "these messages will repeat until I have cancel the script.  Note that even if the message indicates the virtual computer to migrate the virtual machine is migrated nto.


PowerCLI console displays the message "Type: value task: task-1711391" this message will keep scrolling by with the incrementing value by one each time until I have cancel the script. ""




Bonus question, will of the vmx changes made with this script to apply to the virtual machine without turning off due to migration?


Any help will be greatly appreciated.

However, this script seems correct.

You may display the name of the virtual machine to the screen inside the loop, what'd you give an idea if it's a loop on the same VM.

Advanced settings can be applied even if a virtual machine is running.

The vMotion creates a new VMX file, which is recharged and therefore changes must be picked up.

See William post called a kitten is also bad, whenever you change a VMX by hand file

Tags: VMware

Similar Questions

  • By script of the vmx file changes?

    I have a number of existing VMs that I want to add some advanced configuration settings. Instead of using the GUI to add the values, I would like to automate the process. My plan is to write a script that turns off the virtual machine and adds the new values (isolation.tools.x or isolation.device.x) in the vmx files. Is - this safe/advisable to do so via a script? Someone at - it an example of existing script, they would be willing to share?

    If you want to do with just the VI Toolkit itself, then you will need to do something like this

    $vm = get - View (Get - VM NameofVMtoUpdate) USER.USER
    $vmConfigSpec = new-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.extraconfig = new-Object VMware.Vim.optionvalue
    $vmConfigSpec.extraconfig [0]. "Key ="
    lefthandsideofentry"
    $vmConfigSpec.extraconfig [0]. ' Value ='
    rigthhandsideofentry + '.
    $vm. ReconfigVM ($vmConfigSpec)

    Where

    • NameofVMtoUpdate is the name of the virtual machine that you want to update (from the vCenter inventory)

    • lefthandsideofentry is the entrance of advanced configuration, that you want to set

    • rigthhandsideofentry is the value of the advanced configuration entry

    As an alternative some of these people who hang out on the VI Toolkit region have implemented a set of Powershell extensions for the VI toolkit available from CodePlex (http://www.codeplex.com/vitoolkitextensions). Game-TkeVmx will allow you to set values (essentially the same code as above just rolled into a function to keep your code cleaner)

  • AS3 script for editing audio files-

    A wav or mp3 file will be saved or various. Y at - it script to change these files in batch, that is to say: to cut the beginning IE: no sound parts. Or would I need to use a sound editor. As I say, I don't want to do it manually. It sounds like a stupid use, but it is important that I have children themselves taping and cannot use a product of the 3 part to change. AIR got something in an API.

    See you soon

    (b)

  • Best approach to change one. VMX file

    OK, so I can be edited directly a .vmx file (turn off the virtual machine, remove registry vCenter, modify and then re-save).

    You can also use the PowerCLI to add script... But you also have to perform the same steps (as above, i.e.; remove, modify re-register)?

    Finally, is there another approach, for example, a method using the vSphere Client VirtualCenter GUI to add/subtract the selective .vmx file items and/or change their values of (for example) FALSE true?

    Thanks in advance for any advice you can give.

    Do not necessarily remove/add the virtual computer from the inventory, reload command-line will also (see http://kb.vmware.com/kb/1026043)

    I'm not 100% sure with the help of PowerCLI to edit the .vmx file, but I think that since this is done through the API, you don't need to explicitly reload the configuration. Google search for site: communities.vmware.com lucd edit vmx and you will find a large number of samples.

    Some parameters can be changed using the advanced settings of the virtual machine in the vSphere Client.

    André

  • script to check a setting in a vmx file

    I'm relatively new to the thing of powershell and I seek assistance to create a simple script that will analyze by vmx files, search for the disk.enableUUID parameter. We had to put a lot on false to enable backups, and with a new version of the backup software, I'm looking to find those virtual machines, so I can't change back to true... the settings using the advanced settings in the General settings of the virtual machine

    Try something like this

    foreach($vm in Get-VM){
      $vm.ExtensionData.Config.ExtraConfig |  where {$_.Key -eq "disk.enableUUID"} |  select @{N="VM";E={$vm.Name}},@{N="disk.enableUUID";E={$_.Value}}
    }
    
  • Script to change the name of the file to the virtual machine and its associated files

    Hello

    I'm looking for a script to change the name of the virtual machine in virtual center and also change it has associated file names in the data store to match file name of virtual machine. But the vmdk file will contain a descriptor which maps the - flat.vmdk file. So not sure that we can achieve this through a script.

    Thanks in advance!

    Not really as much as I know.

    The advantage of the svMotion is renamed it the files (.) VMX, VMDK,...) For you.

    The only alternative would be the command line. See Duncan Howto: renaming a virtual computer.

    With the help of the plink.exe tool which could possibly be scripted.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • You can edit vmx files on multiple virtual machines in a cluster to allow changes of setting delay start via RCLI or Toolkit VI?

    You can edit vmx files on multiple virtual machines in a cluster to allow changes of setting delay start via RCLI or Toolkit VI? How?

    SAs desire a lead time of 10 seconds through the virtual company composed of several VCs with multiple data centers and clusters.

    Known: we can edit the .vmx file and add: bios.bootDelay = "10000" this adds stunted ms 10000 (10 seconds) when starting

    Known: we may have to re-register or some other mechanism to apply the changes to the start on the VMS settings

    Has anyone tried to make a change of large company to bootDelay on VMS? Any help?

    The script below will do what you want. Have fun.

    -

  • I need a way to search search all the .vmx files

    I have a problem with vMotions in vCenter 6.0 I migrant to ESXi 5.5 with standard switches to a vCenter 6.0 with distributive switches.  For your information, here is the process.

    (1) unplug the host to vCEnter 5.5

    (2) add a host to vCenter 6.0

    (3) migration of ESXI 5.5 to 6.0 ESXi host with the installation of a standard switch.

    4) migrate to 6.0 with standard switch ESXi ESXi 6.0 with D-switch.

    Full migration.  The reason for the double jump is that esxi 55 can't change host and network to a switch-d so I have to get to ESXi 6.0 first.

    It all works very well, but for some reason, the .vmx file doesn't change not the port group. She is always present the standard switch. How ever VMS are on the rise and connected, the web client shows the port of switch-D group.  But when I do a vMotion it changes again in the d switch and the VM crashes.

    I have a case open with VMware to solve this, but I need to get the other VMS migrate without failure.

    The explanation may have been a bit long-winded, but here's what I need.

    I'm OK with PowerCLI but it is a bit outside my experience.  Can we create a script for watching all the ethernet ports in the .vmx for all virtual machines files see what port on their group name?

    Thanks for any help

    Tree!

    Try like this

    Get - VM | Select Name,

    @{N = "PG"; E = {(Get-NetworkAdapter-VM $_ |)} {(Sélectionnez-ExpandProperty NetworkName) - join ' |'}}

  • Odd listing with .vmx file

    I dip a few virtual machines, and I have a script I found online (don't remember who it was, but probably LucD).  The script is not the issue, but the csv file that references the script has some of these lines:

    floppy0. Now, FALSE

    ide0:0. Now, FALSE

    logging, TRUE

    Well, the script seems to work very well, but then when I check the file .vmx avec.extensiondata.config.extraconfig (Get - VM "Name"), the _.key $ for any line that has to do with the virtual material does not appear.  I don't think it's really a problem of script, but this section is so active, that maybe someone can lead me in the right direction, and I used PowerCLI for the settings, so I guess it's relevant.  There are several lines, and everything looks fine except for the material of the lines:

    floppy0. Now, FALSE

    floppy1. Now, FALSE

    ide0:0. Now, FALSE

    ide0:1.present, FALSE

    IDE1:0. Now, FALSE

    IDE1:1.present, FALSE

    parallel0. Now, FALSE

    Serial0.present, FALSE

    Other lines appear when I get back them:

    insulation. Monitor.Control.Disable, true

    insulation. Tools.ghi.AutoLogon.Disable, true

    insulation. BIOS. BBS. Disable, true

    isolation.tools.getCreds.disable, TRUE

    Even if I 'change settings' > Options > advanced. General > Configuration settings and add a line, I can't retrieve it with powershell (only the material lines) if I directly edit the .vmx file and backup copy, these lines do not arise with powershell, but they will appear if I look at the file .vmx Windows with Scripture, or any other text editor.

    If anyone has experienced this?  More important, nobody knows what I'm doing wrong?

    The script is here and there is a CSV file that I use with the examples I listed, he has the key, columns of values correctly

    Line of #This matter the pair key / value for the parameter .vmx

    $import = import-Csv "C:\STIGapply\STIG_current.csv".

    $VMs = get-back STIG | ' Get - VM"* clone.

    $vmConfigSpec = new-Object VMware.Vim.VirtualMachineConfigSpec

    {Foreach ($item in $import)

    $extra = new-Object VMware.Vim.OptionValue

    $extra. Key = $item. Key

    $extra. Value = $item. Value

    $vmConfigSpec.extraconfig += $extra

    }

    {Foreach ($vm to $vms)

    $vm. ExtensionData.ReconfigVM ($vmConfigSpec)

    }

    In ExtraConfig , you will see only the VMX lines that do not have an actual entry in the VirtualMachine object.

    In the case of these systems can be found in $vm. ExtensionData.Config.Hardware.Device.

  • Need help updated the VMX file on several Virtual Machine

    All,

    Can anyone help with a problem I'm having?  Here is a brief explanation of what is happening and what we need to solve.

    Recently we found out that we need to add a line in the file VMX of several virtual machines.  In the past, I was able to do this, but would have cold start the virtual machine for the changes to take effect.  Starts cold won't be a problem, because we can program it.

    However, no one knows a way to add this line in the file VMX virtual machines in a cluster.

    Here's the line I need added:

    Devices.hotplug = "false".

    Here is a script that was used earlier (esx 3.0 days) to keep the VM tools updated on reboot.  At this point, if the virtual machine has been turned on, this change could not do through the UI.  However, this script worked to update the .vmx file and then we have cold reboots for the changes to take effect.

    Get-viserver - < Server > - < user > - < password >

    $viview = get-Cluster-name NOMCLUSTER | Get - VM | foreach-object {get-view ($_.ID)}
    $viview | {foreach-object
    $vmConfigSpec = new-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = new-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.afterPowerOn = 'True '.
    $vmConfigSpec.Tools.afterResume = 'True '.
    $vmConfigSpec.Tools.beforeGuestStandby = 'True '.
    $vmConfigSpec.Tools.beforeGuestShutdown = 'True '.
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle".
    $_. ReconfigVM ($vmConfigSpec)
    }

    The exact script can be found in Disable HotPlug

  • Add .vmx files for inventory

    Hi all

    We have a situation where we try to automate the contribution of virtual machines on our site of DR. Right now we simulate this by using a separate VMFS data store. We use a SAN NetApp reflecting a copy of this course for the DR Datacentre, remove us the mirror, and then mount the VMFS datastore. But what we find is that in the data store, the file needs to be renamed before that we can add vmx to the other site, maybe it's because it still exists in the environment "under tension"? I'm not sure.

    So, what I want to achieve is to have a script that I can specify the data store, cluster and perhaps the resource group, and he gets all the vmx files into this data store. I've seen an excellent script by LucD (attached) which looks perfect but when I run it it does not seem to do anything, but produces also no errors, I think it has something to do with the way in which it is to find the location of the data store, but I'm not sure about this at all.

    I hope that makes sense.

    ##############################
    # These settings

    $dsname = "HS1-DRS-SYS1.
    $datacenter = "mycompany".
    $cluster = "Leeds".
    $virtualcenterserver = "hs1-vmc-001.


    #####################################################################################################
    #Actual script (do not do any changes below this line

    SE connect-VIServer-Server $virtualcenterserver
    $ESXname = get-Cluster $cluster | Get-VMHost | Select - 1 first
    $dsBrowser = get-View (Get-View (Get-VMHost-name $ESXname) USER.USER). DatastoreBrowser
    $folder = get-View (Get-data center-name $datacenter |) Get - Folder - name "vm") USER.USER
    $pool = get-View (Get-Cluster-name $cluster |) Get - ResourcePool - name 'Resources') USER.USER
    #cls
    Write-Host ""
    Write-Host "Welcome to the Recovery System data store"
    Write-Host ""
    Write-Host "this script will now begin adding all THE VMs.
    Write-Host "of the data store" $dsname "on vSphere Server" $virtualcenterserver
    Write-Host ""
    {foreach ($dsImpl to $dsBrowser.Datastore)}
    $ds = get-views $dsImpl
    if($DS.) Summary.Name - not $dsname) {continue}

    $datastorepath = '[' + $ds. Summary.Name + '] '.

    $searchspec = new-Object VMware.Vim.HostDatastoreBrowserSearchSpec
    $searchSpec.matchpattern = '*.vmx.

    Write-Host 'search in the path' $datastorepath

    $task = get-view ($dsBrowser.SearchDatastoreSubFolders_Task ($datastorePath, $searchSpec))
    While ($task.Info.State - eq 'running' - or $task.Info.State - eq 'pending') {}
    $task. UpdateViewData()
    sleep 5
    }
    If ($task.info.result - not $null) {}
    {foreach ($file in $task.info.Result)}

    if($file.) FolderPath - match ".snapshot") {continue}
    $found = $FALSE
    {foreach ($vmx to $vms)
    If (($file.)) FolderPath + $file. File [0]. (Path) - eq $vmx) {}
    Write-Host "" tVM is registered. "
    $found = $TRUE
    }
    }
    If (- not $found - and $task.Info.Result [0].) File - don't $null) {}
    $vmx = $file. FolderPath + $file. File [0]. Path
    $params = @($null, $FALSE, $vmx, $pool.) MoRef, $null)
    Write-Host "Inscription" $vmx
    $folder. GetType(). GetMethod ("RegisterVM_Task"). Invoke ($folder, $params)
    }

    }
    }
    }

    When I run the present to the point where it says 'Welcome in the store of data recovery system' etc. and then nothing comes. I noticed a thread where I got it (thanks again) and it is mentioned and the NFS datastore that we use not, I guess we use the traditional method.

    Furthermore, we use vSphere 4.0.

    I tried to drop the script to understand what it is myself, but nothing works unfortunately and I am now Powershell guru! I noticed that if I run across it caraa the $datastorepath return [].

    Any help with this would be much appreciated.

    Thanks in adavnce

    Julian

    OK, let's check if the DatastoreBrowser is all warehouses data on all nodes.

    This allows to check.

    foreach($esx in Get-Cluster $cluster | Get-VMHost){
        $dsBrowser = Get-View $ESX.ExtensionData.DatastoreBrowser
        foreach($dsObj in $dsBrowser.Datastore){
            $ds = Get-View $dsObj        Write-Host $esx.Name $ds.Name
        }
    }
    
  • Help! Need a script to automatically open files with the same name but in another location.

    Good morning friends,

    So for my work, I need a script to open files with the same name but located in a different folder. But since I'm a total noob when it comes to programming, I can't understand how do. That's what I have in mind:

    -J' I manually open an image.

    -The script will look for a file with the same name in another folder that I've specified.

    -The script will then select the channel CMYK of the second file and copy and paste it into the first file.

    -The second file is then closed without saving the changes.

    I have problems with the part where the script searches for a file with the same name as the opened file. I would really appreciate help. Thanks in advance.

    If (app.documents.length > 0) {}

    myDocument var = app.activeDocument;

    var Nomdoc = myDocument.name;

    try {var basename = docName.match (/(.*)-.)} [ ^\.] +$/)[1]}

    catch (e) {var basename = thedoc.name};

    var path = / * path of folder to insert as a string here * / + ' / ' + base name + / * insert file extension, including the period as a string here * /;

    If (queue (path) .exists == true) {var otherDocument = app.open (File (path))};

    };

  • Add a vmx file entry

    If I add an entry in a file such as Get - VM's vmx | New-AdvancedSetting - name "isolation.tools.diskShrink.disable" - value $true.

    This will require a reboot of the virtual machine to take effect?

    http://www.virtuallyghetto.com/2014/03/a-kitten-is-also-harmed-every-time-you-edit-a-vmx-file-by-hand.html is a good read

    William has an interesting workaround solution using vMotion to cause the changes take effect without needing a reboot (have a read of the last paragraph)

  • construction of a script to change the time syn in vsphere 5.1

    Hello

    I would like to know is possible to create a script that will enable and disable the option vmx file to connect to an NTP server or not?

    to enable the option, the stay a vmx file attached

    Disconnection of the time synchronization option I have to add a cuple of lines in the VMX file:

    tools.syncTime = "FALSE".

    Time.Synchronize.continue = "FALSE".

    Time.Synchronize.Restore = "FALSE".

    Time.Synchronize.Resume.Disk = "FALSE".

    Time.Synchronize.Shrink = "FALSE".

    Time.Synchronize.Tools.Startup = "FALSE".

    Time.Synchronize.Tools.Enable = "FALSE".

    Time.Synchronize.Resume.Host = "FALSE".

    the thing is that I need to create the script to the work of the VM machine that needs the option and the ESXi.

    Kind regards

    Michel V

    There was a typing error in the 2nd "receiving" it's corrected.

    Try again

  • Need to remove the advanced values in VMX file

    Former Director elected to harden all VMs VMX files in order to avoid interruptions in service unwanted individuals manual installation of the VMware tools upgrades.

    I agree with him and understand in previous versions, it was a good idea to disable these but now with 5.1 with the fact that we have more to restart for the modernization of the tools happen my life has become much more complicated and we constantly have problems with VM with mounted tools and no way forced to disassemble the tools.

    I am looking for PowerCLI script to remove these advanced values in the VMX file for all the virtual machines attached to a vCenter. I guess these are the following values:

    isolation.tools.autoInstall.disable = true

    isolation.tools.guestInitiatedUpgrade.disable = false

    insulation. Tools.connectable.Disable =true

    If there are other values that I should check, please let me know and I will review the VMX file.

    This is another option, but lines will remain in the VMX, albeit with different values

    You can do it with this script

    $vm = Get-VM -Name MyVM
    
    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
    
    $extra1 = New-Object VMware.Vim.OptionValue$extra1.Key = "isolation.tools.autoInstall.disable"$extra1.Value = "false"$spec.ExtraConfig += $extra1$extra2 = New-Object VMware.Vim.OptionValue$extra2.Key = "isolation.tools.guestInitiatedUpgrade.disable"$extra2.Value = "true"$spec.ExtraConfig += $extra2$extra3 = New-Object VMware.Vim.OptionValue$extra3.Key = "isolation.tools.connectable.disable"$extra3.Value = "flase"$spec.ExtraConfig += $extra3
    
    $vm.ExtensionData.ReconfigVM($spec)
    

Maybe you are looking for

  • Power 2 Go

    I used Power 2 Go to copy photos on CD - R discs.  After a couple of discs, the writing process stopped at 34% and the program and the computer locked up. I could not close the program, restart the computer, or remove the CD. I had to turn off the PC

  • the hompage I use overlaps the toolbar at the top of the page in half about, how do I change (make lower) it

    When I click to open firefox page (homepage) superimposed on the toolbar at the top of the screen. I've been using the yahoo toolbar that works perfectly, the only problem is this overlap of the site search box Web icons. He is strange as at that mom

  • EA6500 NAT several IP addresses

    I currently have my EA6500 behind verizon fios router. I have 5 static IP addresses to FIOS router, however the machines that I want to connect are behind EA6500. It is a double NAT scenario: Public network 192.168.2.0/24 network 192.168.1.0/24 - EA6

  • Read a utf-8 text file

    Hi, until now, I used the default encoding for reading and writing text files, but I discovered it causes question marks trying to read or write the non-English characters, so I'm trying to change my code to use: inputstramreader and OutputStreamWrit

  • Extend left external display in Windows 7

    Hello Can I extend my external screen to extend to the left of the main screen. ? I was able to do it with Vista but just upgraded to Windows 7 and can't get theat option in Control Panel. Thank you