{"id":3963,"date":"2022-08-18T15:39:57","date_gmt":"2022-08-18T14:39:57","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3963"},"modified":"2022-08-18T15:39:57","modified_gmt":"2022-08-18T14:39:57","slug":"deallocate-azure-ad-joined-azure-virtual-desktop-vms-when-a-user-logs-off","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2022\/08\/deallocate-azure-ad-joined-azure-virtual-desktop-vms-when-a-user-logs-off\/","title":{"rendered":"Deallocate Azure AD Joined Azure Virtual Desktop VMs when a user logs off"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When you shut down a VM or log off, the VM isn&#8217;t actually deallocated and <a href=\"https:\/\/docs.microsoft.com\/en-us\/answers\/questions\/574969\/what39s-the-difference-between-deallocated-and-sto.html\" target=\"_blank\" rel=\"noreferrer noopener\">still costs money<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bernd wrote a <a rel=\"noreferrer noopener\" href=\"https:\/\/techcommunity.microsoft.com\/t5\/azure-virtual-desktop\/deallocate-vm-on-user-logoff\/m-p\/2280211\" target=\"_blank\">nice guide on how to deallocate a VM when a user logs off<\/a>, using GPO&#8217;s, since combined with <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-desktop\/start-virtual-machine-connect?tabs=azure-portal\" data-type=\"URL\" data-id=\"https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-desktop\/start-virtual-machine-connect?tabs=azure-portal\">Start On Connect<\/a> the user experience is still pretty decent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Intune \/ Microsoft Endpoint Manager, no solution was known yet. So I base64 encoded Bernd&#8217;s solution and wrapped it into a SYSTEM wide scheduled task that is triggered by a security eventlog logoff entry.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deploy this to your VM&#8217;s in Intune (either through a user or a machine group) and it&#8217;ll ensure users&#8217; VM&#8217;s get deallocated when they log off.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This also works on shared VM&#8217;s, as it will only deallocate if it is the last user logging off.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can download\/view <a href=\"https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/set-AVDDeallocateOnLogoff.ps1\" target=\"_blank\" rel=\"noreferrer noopener\">set-AVDDeallocateOnLogoff.ps1 here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you shut down a VM or log off, the VM isn&#8217;t actually deallocated and still costs money. Bernd wrote a nice guide on how to deallocate a VM when a user logs off, using GPO&#8217;s, since combined with Start On Connect the user experience is still pretty decent. For Intune \/ Microsoft Endpoint Manager, &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2022\/08\/deallocate-azure-ad-joined-azure-virtual-desktop-vms-when-a-user-logs-off\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Deallocate Azure AD Joined Azure Virtual Desktop VMs when a user logs off<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,5,6,12,22,39],"tags":[],"class_list":["post-3963","post","type-post","status-publish","format-standard","hentry","category-automation","category-azure","category-windows-virtual-desktop","category-ems","category-intune","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3963"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3963\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}