Addition of VMDK to VM in new vSphere PowerCLI

Hi all

This message goes hand in hand with may last post and involve the transfer of uncomfortable the new vSphere PowerCLI from the VItoolkit on VMware 3.5.

One of my scripts uses some functions to add existing VMDK files on an existing virtual machine. The big problem is - this code is a reason any invalid in the CLI of new power.

As you can see - functions have simple command line with VM, VMDK file and the number of SCSI controller. Can someone hazard a guess then that this process is no longer valid for PowerCLI?

Thank you in advance: o)

  1. Functions

# #Examples

      1. Add HD "PC4" "vmfs2" "PC4/PC4.vmdk" "controller SCSI 0".

      2. VM-delete-HD 'name' "disk hard 3" $TRUE ".

function add-HD {}

Param ($VMname, $SCSIcntrl, $DSname, $Filename)

#write - host "adding disc $Filename data $DSname $VMname-VM store."

$vm = get - View (Get - VM $VMname) USER.USER

$ds = get - View (Get-Datastore-name $DSname) USER.USER

{foreach ($dev to $vm.config.hardware.device)}

If ($dev.deviceInfo.label - eq $SCSIcntrl) {}

$CntrlKey = $dev.key

}

}

$Unitnumber = 0

$DevKey = 0

{foreach ($dev to $vm.config.hardware.device)}

If ($dev.controllerKey - eq $CntrlKey) {}

If ($dev. Unitnumber - gt $Unitnumber) {$Unitnumber = $dev. Unitnumber}

If ($dev.key - gt $DevKey) {$DevKey = $dev.key}

}

}

LogEntry $sLogFile 'DeviceKey is $DEVKEY, UnitNUm is $UnitNUmber, ContrlKey is $CntrlKey.

$spec = new-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = @)

$spec.deviceChange += new-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange [0] = new-Object VMware.Vim.VirtualDisk .device

$spec.deviceChange [0].device.backing = new-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.deviceChange [0].device.backing.datastore = $ds. MoRef

$spec.deviceChange [0].device.backing.fileName = "" + $Filename

$spec.deviceChange [0].device.backing.diskMode = "independent_persistent".

$spec.deviceChange [0].device.key = $DevKey + 1

    1. UnitNUmber SCSIID 7 is reserved for the controller - so ignore it and move on to 8.

If ($Unitnumber - eq 6) {$Unitnumber = $Unitnumber + 1}

$spec.deviceChange [0].device.unitnumber = $Unitnumber + 1

$spec.deviceChange [0].device.controllerKey = $CntrlKey

$spec.deviceChange [0] .operation = 'Add '.

$vm. ReconfigVM_Task ($spec)

}

delete-HD {} feature

Param ($VMname, $HDname, $Delflag)

#write-host "' disassembly disk for VM $HDname: $VMname" "

$vm = get - View (Get - VM $VMname) USER.USER

foreach ($dev in $vm. Config.Hardware.Device) {}

If ($dev. DeviceInfo.Label - eq $HDname) {}

$key = $dev. Key

$name = $dev. Backing.FileName

}

}

$spec = new-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = @)

$spec.deviceChange += new-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange [0] = new-Object VMware.Vim.VirtualDevice .device

$spec.deviceChange [0].device.key = $key

$spec.deviceChange [0] .operation = 'delete '.

$vm. ReconfigVM_Task ($spec)

If {($Delflag)

$svcRef = new-object VMware.Vim.ManagedObjectReference

$svcRef.Type = 'ServiceInstance.

$svcRef.Value = 'ServiceInstance.

$serviceInstance = get-views $svcRef

$fileMgr = get-view $serviceInstance.Content.fileManager

$datacenter = (get-View (Get - VM $VMname |)) Get-Datacenter) USER.USER) .get_MoRef)

$fileMgr.DeleteDatastoreFile_Task ($name, $datacenter)

}

}

Below the new versions of my HD - Add and Remove-HD functions.

The functions Add - HD had an error in this line

     $spec.deviceChange[0].device.backing.fileName =" " + $Filename

The function Remove-HD can be optimized in vSPhere.

With the help of the LayoutEx.Disk property, you can now find all the files that are located behind a virtual disk.

The new versions are attached because there are some hooks in the code.

Tags: VMware

Similar Questions

  • Possibility of setting up new vSphere 4 and pass the ESX 3.5 hosts?

    The upgrade path makes me nervous (am I too paranoid?).

    In any case, I have enough material and storage SAN to configure a new vSphere environment.

    Is it possible to install a new enviornemnt and separate vSphere 4 and then migrate the 3.5 environment hosts? The doc has always start with VC upgrade to version 4 and be careful not to break stuff...

    I actually finished a project a few days ago in this respect. I deleted the machine virtual old inventory, moved with the former VM of the LUN to the storage for the new environment group and added to the inventory again. Of course, if you do not use the same storage, it will be more in depth, but it certainly can be done. The plan was to do what weinstein said in his post, regarding the old host to the new Victoria Cross add, but I move the first LUN and had to finish like I did. It went well and I don't have problems with the virtual machine again.

  • MIX the ESX 3.5 and new Vsphere ESX

    Hello

    Please be patient with my questions.

    I have an existing TWO older ESX 3.5 server in a Cluster connected to a SAN switch with dual path.  These two servers are managed by a virtual Center 2.5. These two ESX are connected to a SAN tell LUN1 LUNS in a cluster named Cluster_A

    I will install TWO NEW Vsphere 4.0

    Question 1) when SAN zoning is configured, the current LUN1 can be presented now two new ESX Server because they are of different version?

    Question 2) since the ESX 3.5 required a license server of virtual center still in place, how I installed the license in this virtual Center assuming that I upgrade to vcenter 4 in an environment where I have two esx 3.5 in a clusterA and two esx 4.0 to focus and manage a single VC?

    Question 3) given that I have two ESX 3.5 in ClusterA, let say, I installed two new ESX 4.0 in the same ClusterA, what will be the impact on this type of configuration?

    (> Question 1) when SAN zoning is configured, the current LUN1 can be presented now two new ESX Server because they are a different version?

    Yes.

    (> Question 2) since the ESX 3.5 required a license server of virtual center still in place, how I installed the license in this virtual Center assuming that I upgrade to vcenter 4 in an environment where I have two esx 3.5 in a clusterA and two esx 4.0 to focus and manage a single VC?

    You must allow the license server to 3.5 running even after upgrading vCenter.

    (> Question 3) because I have two ESX 3.5 in ClusterA, let say, I installed two new ESX 4.0 in the same ClusterA, what will be the impact on this type of configuration?

    No, they can operate in the same cluster. But if you want to be able to migrate virtual machines between 4.0 and 3.5 to NOT upgrade from VM hardware version, leaving all virtual machines with hardware VM 4.

    ---

    MCSA, MCTS, VCP, VMware vExpert 2009

    http://blog.vadmin.ru

  • Cannot download - VMware vSphere PowerCLI for tenants

    Hi people,

    I'm not able to download VMware vSphere PowerCLI for the R2 version of tenants i.e. 5.1. Go to the page cannot be displayed.

    Please check.

    Kind regards

    Rajesh

    VMware vSphere PowerCLI for tenants

    Seems to work for me from this link.

    Perhaps a local cache in your browser problem, or a problem of Akamai in your area?

  • New to Powercli

    Hello

    I'm new to powercli and try the Explorer as much as possible. While working with powercli, I don't know how to find the property of members of a cmdlet. For example if I ran the following command on the powercli:

    Get - VM | Get-Member

    We will get a list of members. Now, if I want to use Powerstate member in my script I need to know that this member has two subproperties as receptor and PoweredOff.

    Now, I don't know what are the properties of the Guest member or hard drives etc. So how to find these properties easily so that I can use it as a condition with where-object in my script.

    You can approach this problem with the Format-Custom cmdlet.

    Something like that will show you properties 2 deep levels.

    Get - VM MyVM | Format-Custom *-depth 2

    And if you are only interested in the property of comments, you could do

    Get - VM MyVM | Format-Custom guest - depth 2

  • Auto open when you click on VMware vSphere PowerCLI icon.

    Hello

    Quick question is there a configuration file or a way for me to have powershell cli automaticly "connect-viserver" when I open the icon "VMware vSphere PowerCLI.

    Thank you

    There are several ways to achieve this.

    The best way, in my humble opinion, is to add the Connect-VIServer cmdlet to a PowerShell profile files.

    Just add a line to the file. If you use an authorized account, you can do

    SE connect-VIServer-Server MyServer

    I suggest you use the profile of the current user, in this way that the Connect-VIServer will run only when you start PowerCLI

  • Using Windows Powershell ISE with vSphere PowerCLI

    Hey everybody,

    I'm completely newbieand have just started on the track "managing vSphere with powershell. First problem:

    Is it possible to use Windows Powershell ISE with vSphere cmdlets or can I only use the vSphere PowerCLI?

    I wish I could type my commands directly in the window of the ISE and manage my scripts etc because of this (I find myself n always cut and paste from Notepad when you use the PowerCLI).

    If so, how should I do this?

    I guess its something simple, but when I run the ISE seems not to have registered vSphere cmdlets. I guess I missed something?

    Thank you

    Marc

    In the ISE if you run the following cmdlet, you will get the registered PowerCLI cmdlets:

    Add-PSSnapin "Vmware.VimAutomation.Core".

  • When I open a new window, an additional blank tab opens in the new window.

    The problem started when I reset my new page.
    Because the two legs were open, she defined the second tab in the home page.
    When I noticed this, I reset (choice between bookmarks) with a single tab.
    Unfortunately, it continues to open two tabs, whenever a new window is opened, either when starting Firefox or by a link.
    Pressing 'Home' don't open a new tab.

    One of your FAQs advised removing the characters of pipe in the home page layout, but this does not apply in this case.

    Can you help me?

    Thank you

    Select this option.

    You can drag a single tab on the Home button to set this tab as homepage.

    The extension of MySearchDial has been reported to cause problems with opening of new additional tab.

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance).

    • Do NOT click on the reset button on the startup window Mode without failure.
  • Need help to update to work with the new vSphere environment 6

    I have a great powershell script some time ago, I created to clone our production servers in a development environment and configure them for use in isolated vShield development networks.

    We have recently updated our environment vSphere vSphere 6 and changed architecture autour 5.

    Previously with vSphere 5 we had a unique vCenter server that managed our two datacenters by itself.

    With the new design of vSphere 6, we have a PSC and VCSA server to each data center in one area of SSO.

    The first thing I did with my script of cloning is up-to-date reference vcenter for a table of two servers, so I connect to two VCs at the same time.

    This allows me to see and manage the two vCenters virtual computer guests, so get - vm strives to see the comments of the source.

    However, the problem is that when I try to clone a virtual machine from one data center to another, the command fails because it can't find the virtual machine to clone.

    # Virtual Centre server or VM host to connect to
    $aryVIServer = @("vc01.domain.com", "vc02.domain.com")
    
    # Load VMware environment
    Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
    $VIServer = Connect-VIServer $aryVIServer
    
    # Server cluster group to deploy to
    $strVMCluster = "Bubbles"
    
    # Define name of new server including environment prefix
    $vmName = "$($envPrefix)-$($CloneServer)"
    
    # Select Host with least memory consumption
    $selectedHostObj = Get-VMHost -Location $strVMCluster | Sort-Object -Property MemoryUsageGB | Select-Object -First 1
    
    # Select folder to place VM guest into
    $folderObj = Get-Datacenter -Cluster $strVMCluster | Get-Folder $selectedBubble
    
    # Select datastore with most available space
    $selectedDatastoreObj = Get-DataStore -VMHost $selectedHostObj | Sort-Object -Property FreeSpaceGB -descending | Select-Object -First 1
    
    # Clone new VM from running Server
    $newVM = New-VM -Name $vmName -VM $CloneServer -VMHost $selectedHostObj -Datastore $selectedDatastoreObj -DiskStorageFormat "Thin" -Location $folderObj -Confirm:$false
    

    He used to work very well when there was a single VC but of course does not now with two.

    So far, the only difference is the change in VCs. We always use the same exact 5.0 running ESXi hosts to the same place in separate data centers.

    Oh and I'm now using powercli 6.3 R1 instead of 5.5 R1.

    I look forward to this type of procedure should work fine, and I just need a different command for virtual machine cloning now?

    Well, I have solved the first problem according to them here:

    Re: Impossible to deploy VM model on different vCenter Server (in the same domain of SINGLE sign-on)

    However, now I can't run Invoke VMScript without getting an error that the proxy authentication is required.

    If I remove all my proxy settings in Internet Explorer, then it connects fine but this script must be run by a number of engineers without being dependent on their proxy settings are disabled.

    I can programmatically change the settings of proxy at the beginning of the script, but nothing not preventing to change those back if they use their browser and break execution of the halfway of script.

    Never had any problems with the Proxy settings before and I didn't know any other messages that have directly relevant air.

    Anyone know of a way to avoid this?

  • Create a new vsphere environment 6 and migrate virtual machines to esxi existing 5.1

    The current environment has a cluster with 5.1 esxi hosts and vcenter server 5.5-controlled.

    I would like to create a new environment vsphere 6 with new hosts. Again I mean a clean install of vCenter server 6 and esxi, implementation of the new cluster, etc.. So I won't be able to migrate virtual machines running in 5.1 esxi hosts to the new environment.

    What would be the appropriate steps to make this right?

    Thank you.

    Take a look at this KB on how to move an ESXi host at another vCenter vSphere: VMware KB: move a managed ESX ESXi host to a vCenter Server to a different Server vCenter

    And if you are using vDS, you should look here: KB VMware: ESX/ESXi host with vDS passing a vCenter Server to another

  • svMotion is not rename VMDK disk to the new VM?

    People,

    With 5.1 vSphere update 1

    I've renamed just a newly deployed VM of vSphere Console say oldVMName to the newVMName.

    my understanding is that, after running Storage vMotion, all the components of the virtual machine will be renamed in the newVMname, but somehow, just rename the VMFS directory only?

    svMotion front: oldVMName/oldVMName.vmdk [VMFS_vol_15]

    After svMotion: newVMName/oldVMName.vmdk [VMFS_vol_15]


    How to rename the VMDK match server display name without causing downtime?

    That's what I want to achieve:

    NewVMName/newVMName.vmdk [VMFS_vol_15]

    Yes, you will need a different Storage VMotion to rename the files.

  • New vSphere Windows 2008 R2 Server fails, the installation of the server with error 1920

    Band new installation of Windows Server 2008 R2 SP1 with all updates.

    Try installing vSphere CU2 5.5 Server build 2183112.

    Try the 'Easy install' or 'Custom Installation' I got the following error when the Single Sign-On is trying to settle.

    "Error 1920. Service "VMware Directory Service" (VMWareDirectoryService) failed to start. Check that you have sufficient privileges to start system services. »

    The event log shows this is not much help.

    "VMware Directory Service service failed to start due to the following error:

    Service has failed to demand launch or timely control.

    I have re-uploaded the iso with the same result and even try to install CU1 but who also failed with the same error.

    I tried http://kb.vmware.com/kb/2069695 with the same failed results.

    Setup log is attached.

    Problem has been fixed.

    I hope this solution will help others also (perhaps through a keyword to Google/Bing search)

    Have no Dell Host Integration Toolkit (I 4.7.1) installed when you perform an installation/upgrade of Single Sign-On. Once the VMWare software install then you can install the Dell Host Integration Toolkit.

    According to VMWare Support, this is a known problem (internal documentation) and want to resolve it shortly.

  • New vSphere/vCenter installation problems

    Hi all

    User of long date, but first time poster, so go easy on me.

    So I hit a bit of a weird situation here, I am currently working on a vSphere environment completely new to replace our existing (don't ask, long story).

    Through the documentation and also various other stuff on the web I came with the plan went forward and installation:

    Here's what I did:

    2 separate servers involved, 1 for vcenter server and 1 for the SQL database

    Installation of SQL and ready to go with 2 DB created RSA and VCDB, entry with relevant permissions.

    After installing TS for authentication UNIQUE I went ahead with the installation of SINGLE sign-on, it went through fine. Service accounts used as required and set password, research service sdk admin@System-Domain responds in a browser, etc. etc.

    I then installed the service of inventory, as it went through fine.

    Then, I installed the web client of vsphere that even once went well, and I was able to connect with the admin@System-Domain above account and find that the discovery of AD was detected successfully our field. Large.

    I then added an ad group to the __Administrators__ SSO group. This ad group contains my admin account, after which I was able to connect to the web client with my account.


    Then, I went through installing vCenter server, using the relevant service accounts and connections of databases etc. I used the ad group that I added to the PSO previously for the last step. This completed without error.

    I am now to connect on the web client again, with my account, manage vcenter nothing helps...

    The vCenter server does not appear in the drop-down list in the Administration or in the vcenter section lists. Also, I can not connect to vcenter using the thick client (c#).

    My first thought was that it has not registered with the service of inventory, but I have since reinstalled vCenter Server and installing it told me that there is already a vcenter Server present (I want to delete).

    Anyone have any ideas about where to go from here?

    Thank you

    Jon

    I thought account and you know I had at the bottom of the issue, it was around the fact that our AD has been organized where users and groups are in different locations, and automatically detected in SSO AD settings were not return users correctly. Strange, I know, but it seems that deletion and recreation detected entries with Group dn channels that everything fell into place and slightly modified basic user.

    I thought it was strange to have made this Setup countless times without this kind of question.

  • Purchase new VSphere 5 license... will it work for the old version 5.0?

    I know... it sounds like a really stupid question when I read it aloud.  We recently bought another license for VSphere 5 for a new host, let's add our VM cluster.  Our existing hosts are the patch level of 5.0.0,623860 and from what I've read here that I'm not sure I want to deploy the update 5.1 at this stage.

    I don't remember, but I guess that a 5.0 key would work in 5.1 and vice versa?

    I'm not aware of any new CPU for ESXi 5.1 license keys. The keys should work with all versions 5.x.

    André

  • New Vsphere servers (2), cannot connect with vsphere client

    It's strange, that it is a new construction on 2 new servers. With ESXi5 it really doesn't matter what config install so there is nothing to screw it up, so I did the installation of STD, then tried to connect to the server with the client and I get 'call 'ServiceInstance.RetrieveContent' to object 'ServiceInstance' on the server '10.70.1.20' failed.

    This happens on both servers.

    Other messages suggest it is because of the attempts to connect using HTTP instead of HTTPS, but I do not use a prefix, just the IP address.

    If I type the IP address of the server in a browser, I get the standard server ESXi web page so IP connectivity is fine.

    The other strange bits is that I have 3 ESXi 5 server to different hardware built using the same media that works well.

    The vi client log shows this:

    < type = "VirtualInfrastructure.Exceptions.ConnectionError error" >
    < message > the customer has not received a full response from the server "10.70.1.20". (The underlying connection was closed: an unexpected error occurred during the reception.) < / message >
    < InnerException type = "System.Net.WebException" >
    < message > the underlying connection was closed: an unexpected error occurred on a receive. < / Message >
    < InnerException type = "System.IO.IOException" >
    < message > received an unexpected EOF or 0 bytes of the transport stream. < / Message >
    < / InnerException >
    < Status > ReceiveFailure < / status >
    (snipped)
    If I enable SSH and SSH on the server, try PuTTY gives me an error 'incoming packet was scrambled on decryption.
    It seems therefore that encryption is screwed somehow, but since I can't connect to the server I'm strugglin for troubleshooting options?
    Any ideas?

    https://www.VMware.com/support/vsphere5/doc/vSphere-ESX-vCenter-Server-50-release-notes.html

    From the release notes:

    Using the env of BE2/BE2 Emulex Group (pilot be2net)
    When using vSphere 5.0 with Emulex BE2/BE3 NIC (pilot be2net) in an environment FlexFabric/Flex-10 HP or IBM Virtual fabric adapter (VFA), connectivity may not work properly on virtual machines Windows or server when them VLAN is configured.

    Workaround: Do not use the driver included with vSphere 5.0. Before the upgrade to vSphere 5.0, you can get an updated of Emulex, HP or IBM driver that should be used on HP FlexFabric/Flex-10 or IBM VFA systems.

Maybe you are looking for