{"id":308,"date":"2022-03-16T19:56:32","date_gmt":"2022-03-16T17:56:32","guid":{"rendered":"https:\/\/my-virt.alfadir.net\/?p=308"},"modified":"2022-03-16T20:00:08","modified_gmt":"2022-03-16T18:00:08","slug":"list-template-and-snapshot-and-push-new-images-by-script","status":"publish","type":"post","link":"https:\/\/my-virt.alfadir.net\/index.php\/2022\/03\/16\/list-template-and-snapshot-and-push-new-images-by-script\/","title":{"rendered":"List Parent VMs and Snapshots and push new images by script"},"content":{"rendered":"\n<p>I recently had to upgrade a Horizon infrastructure with around 180 pools and different masters, as you can imagine, that could be exhausting first to check which master is  in use and what&#8217;s the current snapshot as well, so after searching a little bit on the Net, I&#8217;ve able to find what I need :<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>So the first thing is to retrieve master and snapshot used per pools and save it to a CSV file using this script initially created by Ivo Beerens (<a rel=\"noreferrer noopener\" href=\"https:\/\/www.ivobeerens.nl\/\" target=\"_blank\">https:\/\/www.ivobeerens.nl\/<\/a>) and slightly modified by me to redirect the output to a CSV file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;#\n.SYNOPSIS\n    PoolParentSnapShot.ps1\n.VERSION\n    1.0\n.DESCRIPTION\n    Exports all Horizon pools with the parents and active snapshot \n.NOTES\n    Author(s): Ivo Beerens (https:\/\/www.ivobeerens.nl\/)\n    Requirements:  \n    Make sure the VMware.HV.Helper module is installed, see: https:\/\/github.com\/vmware\/PowerCLI-Example-Scripts\n    Copy the VMware.Hv.Helper to the module location.\n\tModified by : Eric Monjoin\n\tModification : export to csv \n.EXAMPLE\n    PS&gt; .\/PoolParentSnapShot.ps1\n#&gt;\n\nImport-Module VMware.Hv.Helper\n\n#Variables\n$conserver = 'myconserver.mydomain.dom'\n$domain = 'mydomain.dom'\n\n# Connect to Horizon Connection Server\nWrite-Output \" \", \"Connect to the Connection Server\" \nConnect-HVServer -Server $conserver -Domain $domain\n\n$pools = (Get-HVPool).base.name\n\n$myCol = @() # Create empty array\nForEach ($pool in $pools) {\n        $poolname = Get-HVPool -PoolName $pool\n        $row = \" \" | Select-Object PoolName, Parent, Snapshot \n        $row.PoolName = $pool\n        $row.Parent = $poolname.AutomatedDesktopData.VirtualCenterNamesData.ParentVmPath\n        $row.Snapshot = $poolname.AutomatedDesktopData.VirtualCenterNamesData.SnapshotPath\n        $myCol += $row\n\n    }\n#Write-Output $myCol | Format-Table -AutoSize\n$myCol | Export-csv .\\PoolParentSnapShot.csv\n\nDisconnect-HVServer * -Confirm:$false<\/code><\/pre>\n\n\n\n<p>This give me this output :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"226\" src=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-1024x226.png\" alt=\"\" class=\"wp-image-309\" srcset=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-1024x226.png 1024w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-300x66.png 300w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-768x170.png 768w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image.png 1032w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now, I can modify the file by removing pools I don&#8217;t want to update (eg. RDS Desktop pool), removing all path to snapshot and Parent VM and specify the new snapshot I want to deploy (for a single parent VM, all snapshots name should be different as we only specify its name) :<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-5.png\" alt=\"\" class=\"wp-image-314\" width=\"784\" height=\"177\" srcset=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-5.png 784w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-5-300x68.png 300w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-5-768x173.png 768w\" sizes=\"(max-width: 784px) 100vw, 784px\" \/><\/figure>\n\n\n\n<p>Finally I created this script to automatically push all new images :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;#\n.SYNOPSIS\n    PushNewImage.ps1\n.VERSION\n    1.0\n.DESCRIPTION\n    Push a new images to multiple Horizon Pools \n.NOTES\n    Author(s): Eric Monjoin\n    Requirements:  \n    Make sure the VMware.HV.Helper module is installed, see: https:\/\/github.com\/vmware\/PowerCLI-Example-Scripts\n    \n.EXAMPLE\n    PS&gt; .\/PushNewImage.ps1\n#&gt;\n\nImport-Module VMware.Hv.Helper\n\n#Variables\n$conserver = 'myconserver.mydomain.dom'\n$domain = 'mydomain.dom'\n$csvfile = \".\\PoolParentSnapShot.csv\"\n\n# Connect to Horizon Connection Server\nWrite-Output \" \", \"Connect to the Connection Server\" \nConnect-HVServer -Server $conserver -Domain $domain\n\n$pools = Import-Csv $csvfile -Delimiter ','\nForEach ($pool in $pools) {\n$poolname = $($pool.PoolName)\n$parentVM = $($pool.Parent)\n$snapshot = $($pool.Snapshot)\n\nStart-HVPool -SchedulePushImage -Pool $poolname -LogoffSetting WAIT_FOR_LOGOFF -ParentVM $parentVM -SnapshotVM $snapshot\n\n} \n\nDisconnect-HVServer * -Confirm:$false<\/code><\/pre>\n\n\n\n<p>Once variable are correctly specified, just launch the script (task will be done in the background) :<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"983\" height=\"571\" src=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-3.png\" alt=\"\" class=\"wp-image-312\" srcset=\"https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-3.png 983w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-3-300x174.png 300w, https:\/\/my-virt.alfadir.net\/wp-content\/uploads\/2022\/03\/image-3-768x446.png 768w\" sizes=\"(max-width: 983px) 100vw, 983px\" \/><\/figure>\n\n\n\n<p>Note : <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>I&#8217;d recommend to do it by 50 pools, in our case we pushed it to 170 pools in one shot with few VMs in each and the last 30 failed because of time out.  Not a big problem as we ran again the first script to check which one were not updated.<\/li><li>Don&#8217;t forget to remove any path for the snapshot (so don&#8217;t specify previous one) but also for the parent VM otherwise the deployment will fail<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I recently had to upgrade a Horizon infrastructure with around 180 pools and different masters, as you can imagine, that could be exhausting first to check&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,36],"tags":[14,11],"class_list":["post-308","post","type-post","status-publish","format-standard","hentry","category-horizon","category-powershell","tag-horizon","tag-vmware"],"_links":{"self":[{"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/posts\/308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":2,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"predecessor-version":[{"id":316,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/posts\/308\/revisions\/316"}],"wp:attachment":[{"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my-virt.alfadir.net\/index.php\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}