Automation

 View Only
  • 1.  PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 03, 2024 04:36 PM

    Hi, I'm trying to migrate VM across vcenter using the move-VM cmdlet and it's working fine but then I came across VM that have multiple disk on multiple datastore and then my plane crashed. I'm using this script that I built with the help of ChatGPt but after many tries we couldn't adjust the script to work with multiple disk on multiple datastore

    I'm attaching the working script for standard VM with only 1 datastore and the bad script for cross-vcenter with multiple datastore. The error output by the second script is this:

    "VMName","ErrorMessage"
    "SQL-04","Exception lors de l'appel de « RelocateVM_Task » avec « 2 » argument(s) : « The object 'vim.Datastore:datastore-261' has already been deleted or has not been completely created »"

    I know I could move this VM manually by mapping the appropriate disk but I have other VMs that have 40+ datastore and that is what i'm trying to avoid to manually map by testing on this simple vm with 2 disks.


    Here are some more detail from the debug I thought should help, the destination host is found and has access to the datastore, both disk and corresponding datastore are also in the relocationSpec variable. 

    [DBG]: PS F:\>> $relocationSpec


    Service      : 
    Folder       : 
    Datastore    : 
    DiskMoveType : 
    Pool         : 
    Host         : HostSystem-host-1326
    Disk         : {2000, 2001}
    Transform    : 
    DeviceChange : 
    Profile      : 
    CryptoSpec   : 
    LinkedView   : 

    Using destination host: esx8-10, MoRef: HostSystem-host-1326

    [DBG]: PS F:\>> 
    Migrating VM 'SQL-04' with specified disk mappings

    [DBG]: PS F:\>> 

    [DBG]: PS F:\>> 
    Failed to migrate VM 'SQL-04'. Error: Exception lors de l'appel de « RelocateVM_Task » avec « 2 » argument(s) : « The object 'vim.Datastore:datastore-261' has already been deleted or has not been completely created »

    [DBG]: PS F:\>> 

    [DBG]: PS F:\>> 
    Error details: Exception lors de l'appel de « RelocateVM_Task » avec « 2 » argument(s) : « The object 'vim.Datastore:datastore-261' has already been deleted or has not been completely created »



  • 2.  RE: PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 04, 2024 03:40 AM

    Although I have an aversion to fixing ChatGpt code, the error message indicates that one of the datastores, probablya target, isn't a valid datastore.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 3.  RE: PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 04, 2024 09:28 AM

    Hi, well i made a lot of test and added more diagnostic logging to the script and both the source and destination datastore exist and are I can confirm using this line as when I run the script in debug mode I see the $destds variable containing the datastore:
    $destDS = Get-Datastore -Name $destDSName -Server $destVC

    Also the relocationspec variable contain both the datastore. Do you have a command example on how to migrate a vm with multiple disk in multiple datastore and I can work with that as I couldn't find anything in the help or in my search on how to pass multiple datastore mapping to a move-vm command hence why I resorted to use chatGPT.




  • 4.  RE: PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 04, 2024 09:36 AM

    Did you stop/start your PS session?
    That error sometimes appears when some session data is corrupted.

    Since the migration seems to work from the Web Client, did you already try Code Capture to see which code the Web CLient generates?



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 5.  RE: PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 04, 2024 09:46 AM

    wow, that's new to me, I didn't event knew we could do code capture to transform GUI action into powercli command. I will look into that righ now. Thanks for the pointer.




  • 6.  RE: PowerCli - Cross vcenter vmotion multiple disk on multiples datastores

    Posted Jul 04, 2024 12:22 PM
      |   view attached

    Well just an update that the code capture is not really usefull as it's totally not human friendly, it use a bunch of static mapping with no explantion of what does what and it seem to connect mostly to the source vcenter based on the UID i checked. I may not be a programmer but I do have basic scripting understanding and this is very hard to understand when there is no explanation so I think i will just move the VM using the old manual way by just moving 1 of the host from the old vcenter and connect it to the new vcenter before doing a regular vmotion to a new host in the new vcenter for the vm that have multiple datastore.


    Attachment(s)