SCVMM V2V and Powershell

I have been working for a customer to create a way to migrate VMWare virtual machines. After many attempts, the only consistent and “schedulable” way to do it was to previously convert them from VMWare using VMWare Converter and then run the script below.


The command line is:

.v2v2.ps1 “VMM Host” “Machine Name” “Host Path” “VM machine path in the library” VLanID “VM Description” “Logical Network Name” “Library Server FQDN” “Virtual Switch Name” “Destination Machine Name” “Cloud Name” “Self-Service Owner” “UserRole to share the machine with”

The VMM server name is hardcoded:


See the example below:

.v2v2.ps1 “Server.domain.local” “MachineName” “C:ClusterStorageVolume1” “\vmarchive.domain.localVMARCHIVEESX-1MachineName” 1 “” “Production” “vmarchive.domain.local” “Network Trunk” “” “MyCloud” “domainuser1” “Production Users”


param (
[string]$VirtualNetworkName=”Network Trunk”,
# .v2v2.ps1 “Server.domain.locall” “MachineName” “C:ClusterStorageVolume1” “\vmarchive.domain.localVMARCHIVEESX-1MachineName” 1 “” “Production” “vmarchive.domain.local” “Network Trunk” “” “MyCloud” “domainuser1” “Production Users”
import-module virtualmachinemanager
if ($DestinationMachineName -eq “” -or $DestinationMachineName -eq $Null)
if ($VMDescription=”” -or $VMDescription -eq $Null)
$VMDescription = $VMName
write-output “Converting VMWare Machine”
write-output “Host Name: $HostName”
write-output “VM Name: $VMName”
write-output “Host Path: $HostPath”
write-output “VM Location: $VMLocation”
write-output “VLAN ID: $VLANId”
write-output “VM Description: $VMDescription”
write-output “Logical Network: $LogicalNetworkName”
write-output “Library Server: $LibraryServer”
write-output “Virtual Network: $VirtualNetworkName”
write-output “Cloud Name: $CloudName”
write-output “Machine Owner: $SelfServiceOwner”
write-output “User Role to Share with: $UserRoleToShare”
$JobGroupID = [Guid]::NewGuid().ToString()
$VMHost = Get-SCVMHost -VMMServer $VMMServer | where {$_.Name -eq $HostName}
$VM = Get-SCVirtualMachine -VMMServer $VMMServer | where {$_.Name -eq $VMName -and $_.LibraryServer.Name -eq $LibraryServer} #| where {$_.Location -eq $VMLocation}
if ($VM -ne $Null)
$VirtualNetwork = Get-SCVirtualNetwork -VMMServer $VMMServer -Name $VirtualNetworkName | where {$_.VMHostID -eq $VMHost.ID}
if ($VirtualNetwork -ne $Null)
$VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -VMMServer $VMMServer -All | where {$_.Name -eq $VMName}
if ($VirtualNetworkAdapter -ne $Null)
$LogicalNetwork = Get-SCLogicalNetwork -VMMServer $VMMServer -Name $LogicalNetworkName
New-SCV2V -VMMServer $VMMServer -VMHost $VMHost -RunAsynchronously -JobGroup $JobGroupID -VM $VM -VirtualNetwork $VirtualNetwork -VirtualNetworkAdapter $VirtualNetworkAdapter -LogicalNetwork $LogicalNetwork
$NewVM=New-SCV2V -VM $VM -VMHost $VMHost -Path $HostPath -Name $DestinationMachineName -Description $VMDescription -JobGroup $JobGroupID -Trigger -CPUCount $VM.CPUCount -MemoryMB $VM.Memory -StartAction NeverAutoTurnOnVM -StopAction SaveVM -StartVM
if ($NewVM -ne $Null)
$NewVM | Get-SCVirtualNetworkAdapter | Set-SCVirtualNetworkadapter -VLanID $VLANId
$Cloud=get-sccloud -Name $CloudName
$UserRole=get-scuserrole -Name $UserRoleToShare
$NewVM | Set-SCVirtualMachine -Cloud $Cloud -Owner $SelfServiceOwner -UserRole $UserRole
Grant-SCResource -Resource $NewVM -UserRoleID $UserRole.ID
else { Write-Output “Failed to create VM $VMName. See job status for details.”}
else { Write-Output “No Virtual Network Adapters found for VM $VMName”}
else { Write-Output “Virtual Network $VirtualNetworkName not found”}
else { Write-Output “The VM $VMname was not found” }


Hope it helps and be careful copying and pasting quotes and dashes!