{"id":324,"date":"2011-04-26T10:39:46","date_gmt":"2011-04-26T14:39:46","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=324"},"modified":"2011-04-26T10:39:46","modified_gmt":"2011-04-26T14:39:46","slug":"migrate-virtual-machines-and-enable-thin-provisioning","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/migrate-virtual-machines-and-enable-thin-provisioning\/","title":{"rendered":"Migrate virtual machines and enable thin provisioning"},"content":{"rendered":"<p>I recently used this code to move a couple dozen terabytes of virtual machines from one array to another &#8212; all while enabling thin provisioning (aka sparse disk).  Once the LUN migration is complete a nice little message shows up in your email.  It is a very straight forward script that I thought was worth sharing.<\/p>\n<pre><code class=\"language-powershell\">\r\n$startTime = get-date\r\n$sourceDS = \"array1-1000\"\r\n$destDS = \"array2-3000\"\r\n\r\n$dsView = Get-Datastore -Name $destDS | Get-View -Property Name\r\n\r\nGet-VM -Datastore $sourceDS | sort name | % {\r\n\t$vmView = $_ | Get-View -Property Name\r\n\t$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec\r\n\t$spec.datastore =  $dsView.MoRef\r\n\t$spec.transform = \"sparse\"\r\n\t$vmView.RelocateVM($spec, $null)\r\n}\r\n\r\nSend-MailMessage -From \"vmware@mydomain.local\" -SmtpServer \"smtp.mydomain.local\" -Subject \"Migration from $sourceDS to $destDS complete\" -To \"me@mydomain.local\" -BodyAsHtml \"This task started at $($startTime.datetime.tostring()) and finished at $((get-date).datetime.tostring())\"\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I recently used this code to move a couple dozen terabytes of virtual machines from one array to another &#8212; all while enabling thin provisioning (aka sparse disk). Once the LUN migration is complete a nice little message shows up &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/migrate-virtual-machines-and-enable-thin-provisioning\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-324","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=324"}],"version-history":[{"count":2,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/324\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/324\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}