<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic VM datastore clone testing using Powershell in Application Integration</title>
    <link>https://community.hpe.com/t5/application-integration/vm-datastore-clone-testing-using-powershell/m-p/6982300#M183</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;been working with VM datastore cloning and running syspreps so i've made a couple of scripts, first one is to run a customization template on all VMs on the new datastore and the other is to remove those VMs and remove the DS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cleanup uses a Nimble PowerShell module I created&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/jrich523/NimblePowerShell" title="https://github.com/jrich523/NimblePowerShell"&gt;jrich523/NimblePowerShell · GitHub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will import all the VMs and rename and sysprep them. there are some assumptions on the template name and how i want the new names to be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$vmhost = "hostname"&lt;/P&gt;&lt;P&gt;$networkname = "network adapter name"&lt;/P&gt;&lt;P&gt;$dsname = "CloneTest2" ##whatever you named your new clone&lt;/P&gt;&lt;P&gt;$instance = "Dev3" ## Im cloning for development env, this and the next two var's are just for how we build computer names&lt;/P&gt;&lt;P&gt;$id = "D3"&lt;/P&gt;&lt;P&gt;$Prefix = "TUK"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#get all VMX (vm's) on the datastore&lt;/P&gt;&lt;P&gt;$vmxs = gci vmstore:\$((Get-Datacenter).name)\$dsname -Recurse -Include *.vmx | select -exp datastorefullpath&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;foreach($vmx in $vmxs)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $currentname = ($vmx -split "/|\.")[1]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $name = "$Prefix$ID$currentname"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $currentVM = get-vm $currentname&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #$os is used to pick the customization template&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $os = if($currentVM.Guest.OSFullName -match "(20\d\d)"){$matches[1]}else{Write-Error "cant find OS version" -ea Stop}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #set location&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $vm = new-vm -Name $name -VMFilePath $vmx -VMHost $VMhost -ea Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set-VM -VM $vm -OSCustomizationSpec "$os-NP-Dev" -Confirm:$false -ea Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $networkname -StartConnected $true -Confirm:$false&amp;nbsp; -ea stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # the start will toss a question error but i cant answer the question until i attempt to start it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start-VM $vm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-VMQuestion -VM $vm | Set-VMQuestion -DefaultOption -Confirm:$false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;once the test is complete and I want to clean up, I run this, which relies on the module. Im going to look in to using the module to do the cloning as well to hopefully get a VSS consistent snap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$dsname = "CloneTest2"&amp;nbsp; ##clone name&lt;/P&gt;&lt;P&gt;$arrayIP = "192.168.1.10"&lt;/P&gt;&lt;P&gt;$password = "arraypassword"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get-VM -Datastore $dsname | stop-vm -Confirm:$false -ea 0 | Remove-VM -Confirm:$false&amp;nbsp; ## remove all VMs on DS from inventory&lt;/P&gt;&lt;P&gt;sleep 2&lt;/P&gt;&lt;P&gt;Remove-Datastore $dsname -Confirm:$false -VMHost $vmhost&lt;/P&gt;&lt;P&gt;Connect-NSArray -SystemName $arrayIP -Password $password&lt;/P&gt;&lt;P&gt;Remove-NSVolume -Name CloneTest2 -Force&lt;/P&gt;&lt;P&gt;Remove-NSSnapShot -Name CloneTest2 -Volume CloneTest -Force&lt;/P&gt;&lt;P&gt;Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any suggestions/input/question would be great&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Jun 2013 16:31:52 GMT</pubDate>
    <dc:creator>jrich52352</dc:creator>
    <dc:date>2013-06-27T16:31:52Z</dc:date>
    <item>
      <title>VM datastore clone testing using Powershell</title>
      <link>https://community.hpe.com/t5/application-integration/vm-datastore-clone-testing-using-powershell/m-p/6982300#M183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;been working with VM datastore cloning and running syspreps so i've made a couple of scripts, first one is to run a customization template on all VMs on the new datastore and the other is to remove those VMs and remove the DS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cleanup uses a Nimble PowerShell module I created&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/jrich523/NimblePowerShell" title="https://github.com/jrich523/NimblePowerShell"&gt;jrich523/NimblePowerShell · GitHub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will import all the VMs and rename and sysprep them. there are some assumptions on the template name and how i want the new names to be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$vmhost = "hostname"&lt;/P&gt;&lt;P&gt;$networkname = "network adapter name"&lt;/P&gt;&lt;P&gt;$dsname = "CloneTest2" ##whatever you named your new clone&lt;/P&gt;&lt;P&gt;$instance = "Dev3" ## Im cloning for development env, this and the next two var's are just for how we build computer names&lt;/P&gt;&lt;P&gt;$id = "D3"&lt;/P&gt;&lt;P&gt;$Prefix = "TUK"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#get all VMX (vm's) on the datastore&lt;/P&gt;&lt;P&gt;$vmxs = gci vmstore:\$((Get-Datacenter).name)\$dsname -Recurse -Include *.vmx | select -exp datastorefullpath&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;foreach($vmx in $vmxs)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $currentname = ($vmx -split "/|\.")[1]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $name = "$Prefix$ID$currentname"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $currentVM = get-vm $currentname&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #$os is used to pick the customization template&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $os = if($currentVM.Guest.OSFullName -match "(20\d\d)"){$matches[1]}else{Write-Error "cant find OS version" -ea Stop}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #set location&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $vm = new-vm -Name $name -VMFilePath $vmx -VMHost $VMhost -ea Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set-VM -VM $vm -OSCustomizationSpec "$os-NP-Dev" -Confirm:$false -ea Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $networkname -StartConnected $true -Confirm:$false&amp;nbsp; -ea stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # the start will toss a question error but i cant answer the question until i attempt to start it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start-VM $vm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-VMQuestion -VM $vm | Set-VMQuestion -DefaultOption -Confirm:$false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;once the test is complete and I want to clean up, I run this, which relies on the module. Im going to look in to using the module to do the cloning as well to hopefully get a VSS consistent snap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$dsname = "CloneTest2"&amp;nbsp; ##clone name&lt;/P&gt;&lt;P&gt;$arrayIP = "192.168.1.10"&lt;/P&gt;&lt;P&gt;$password = "arraypassword"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get-VM -Datastore $dsname | stop-vm -Confirm:$false -ea 0 | Remove-VM -Confirm:$false&amp;nbsp; ## remove all VMs on DS from inventory&lt;/P&gt;&lt;P&gt;sleep 2&lt;/P&gt;&lt;P&gt;Remove-Datastore $dsname -Confirm:$false -VMHost $vmhost&lt;/P&gt;&lt;P&gt;Connect-NSArray -SystemName $arrayIP -Password $password&lt;/P&gt;&lt;P&gt;Remove-NSVolume -Name CloneTest2 -Force&lt;/P&gt;&lt;P&gt;Remove-NSSnapShot -Name CloneTest2 -Volume CloneTest -Force&lt;/P&gt;&lt;P&gt;Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any suggestions/input/question would be great&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 16:31:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/application-integration/vm-datastore-clone-testing-using-powershell/m-p/6982300#M183</guid>
      <dc:creator>jrich52352</dc:creator>
      <dc:date>2013-06-27T16:31:52Z</dc:date>
    </item>
  </channel>
</rss>

