Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Script error when trying to move vms to their dedicated folders

$
0
0

Hello,

 

I am having issues when using a script to move VMs from the Discovered VMs folder to their dedicated VM folders as they were on the old vCenter. I already recreated the folder structure on the new vCenter.

 

The csv from where i am importing is on the form:

 

Name  Path

 

vm1     DatacenterFolderName\folder1\folder2\vm1

vm2     DatacenterFolderName\folder2\folder3\vm2 etc

 

The script is the following:

 

Get-Module -Name VMware* -ListAvailable | Import-Module

If ($globale:DefaultVIServers ) {

Disconnect-VIServer -Server $global:DefaultVIServers -Force

}

 

$destVI = Read-Host "Please enter name or IP address of the destination Server"

$datacenter = Read-Host "DataCenter name in VC"

$creds = get-credential

connect-viserver -server $destVI -Credential $creds

 

# move the vm's to correct location

$VMfolder = @()

$VMfolder = import-csv "c:\csv-files\test\04-$($datacenter)-vms-with-FolderPath.csv" | Sort-Object -Property Path

 

foreach($guest in $VMfolder){

$key = @()

$key =  Split-Path $guest.Path | split-path -leaf

if ($key -eq $datacenter) {

Write-Host "Root folder $guest.path"

#

Move-VM (Get-VM $guest.Name) -Destination "vm"

}

else

{

Move-VM (Get-VM $guest.Name) -Destination (Get-folder $key)

}

}

 

Disconnect-VIServer "*" -Confirm:$False

 

and the error i am getting is the following:

 

Move-VM : 10/19/2018 7:50:24 AM Move-VM Server task failed: The request refers to an unexpected or unknown type.

At C:\Users\username\Desktop\CheapDisasterRecovery\import-05-move-vms-folders.ps1:27 char:3

+         Move-VM (Get-VM $guest.Name) -Destination (Get-folder $key)

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException

    + FullyQualifiedErrorId : Security_Impl_TaskResultConverter_TaskNotSucceeded,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

 

Can someone let me know what i am doing wrong or if there is something that needs to be modified to make it work?

 

The original vCenter is 5.5 and the destination vCenter is 6.5.

 

Thank you.


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>