{"id":1693,"date":"2023-02-18T13:31:13","date_gmt":"2023-02-18T13:31:13","guid":{"rendered":"https:\/\/thecloudwiki.com\/?p=1693"},"modified":"2023-02-18T13:37:38","modified_gmt":"2023-02-18T13:37:38","slug":"horizon-cloud-run-once-script","status":"publish","type":"post","link":"https:\/\/thecloudwiki.com\/?p=1693","title":{"rendered":"Horizon Cloud &#8211; Run Once Script"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_91 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6b0a4173f2aff\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6b0a4173f2aff\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/thecloudwiki.com\/?p=1693\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/thecloudwiki.com\/?p=1693\/#How_to_create_a_run_once_script_%E2%80%93_Example\" >How to create a run once script &#8211; Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/thecloudwiki.com\/?p=1693\/#Why_%E2%80%9Cshutdown_r_t_0_%E2%80%9D_is_mandatory_at_the_end\" >Why &#8220;shutdown \/r \/t 0 &#8221; is mandatory at the end<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/thecloudwiki.com\/?p=1693\/#How_the_Dedicated_assignment_flow_works\" >How the Dedicated assignment flow works<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/thecloudwiki.com\/?p=1693\/#How_the_floating_assignment_flow_works\" >How the floating assignment flow works<\/a><\/li><\/ul><\/nav><\/div>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span><strong><span style=\"text-decoration: underline\" class=\"underline\">Introduction<\/span><\/strong> <span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Run Once is an optional component while creating an assignment and it has many uses<br>In this article , I would like to discuss about how this works for dedicated &amp; floating assignments in Horizon Cloud<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most of the admins are using run once to update the group policies as soon as domain join completes so that all organisation level polices will get updated with VDI creation itself , not only for group policy updates &#8211;  it can be used to run one time scripts to set policies , registry keys , create folders &amp; etc<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_create_a_run_once_script_%E2%80%93_Example\"><\/span><strong><span style=\"text-decoration: underline\" class=\"underline\">How to create a run once script &#8211; Example<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As a best practice , create a folder for run once scripts in the base image &#8211; Ex: C:\\runonce<\/li>\n\n\n\n<li>Open a notepad or an equivalent editor to create the script<\/li>\n\n\n\n<li>At the beginning in the first line type as &#8211; @echo off&nbsp;<\/li>\n\n\n\n<li>now enter the command that you would like to run at start up &#8211; Ex: &#8220;cmd.exe \/k &#8220;gpupdate \/force&#8221;<\/li>\n\n\n\n<li>Don&#8217;t forget to add<em><strong> shutdown \/r \/t 0<\/strong><\/em> at the bottom of script<\/li>\n\n\n\n<li>End the last line by typing &#8211; exit<\/li>\n\n\n\n<li>Save the file as &lt;name&gt;.bat &#8211; Ex: runonce.bat<\/li>\n\n\n\n<li>copy the path of the runonce script to input into assignment creation wizard &#8211; Ex: C:\\runonce\\runonce.bat<br><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_%E2%80%9Cshutdown_r_t_0_%E2%80%9D_is_mandatory_at_the_end\"><\/span><strong><span style=\"text-decoration: underline\" class=\"underline\">Why &#8220;<em>shutdown \/r \/t 0<\/em> &#8221; is mandatory at the end<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The runonce script always runs only after the sysprep<\/li>\n\n\n\n<li>Once after the sysprep , at the time of domain join &#8211; horizon agent in the VM get the path of runonce specified in the assignment <\/li>\n\n\n\n<li>Horizon agent sets the runonce path in the windows registry and restarts the vm to complete the domain join<\/li>\n\n\n\n<li>After the restart , system logs in to operating system with local admin credentials and runs this script<\/li>\n\n\n\n<li>If we won&#8217;t specify the restart command after the commands run the vm not usable for user logins till manually restarted<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_the_Dedicated_assignment_flow_works\"><\/span><strong><span style=\"text-decoration: underline\" class=\"underline\">How the Dedicated assignment flow works<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Based on my testing , the flow works something like below <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">      - VM clone success\n      - wait till machine boots up and sysprep completes\n      - Agent will rename the computer with desired one &amp; domain join \n      - Add runonce script path to registry - set the autologon \n      - reboot the machine\n      - Auto logon with local admin credentials\n      - execute Runonce script &amp; restart<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_the_floating_assignment_flow_works\"><\/span><strong><span style=\"text-decoration: underline\" class=\"underline\">How the floating assignment flow works<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Based on my testing , the flow works something like below <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">      - VM clone success\n      - wait till machine boots up and sysprep completes\n      - Agent will rename the computer with desired one &amp; domain join\n      - Add runonce script path to registry - set the autologon \n      - reboot the machine\n      - Snapshot\n      - Auto logon with local admin credentials\n      - execute Runonce script &amp; restart<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the DAAS if you see any inconsistencies with floating desktops flow- please follow below VMware KB for best practices <br><br><a href=\"https:\/\/kb.vmware.com\/s\/article\/87668\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/kb.vmware.com\/s\/article\/87668<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Run Once is an optional component while creating an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1694,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[21],"tags":[13],"class_list":["post-1693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-horizon","tag-horizon"],"uagb_featured_image_src":{"full":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-e1676727439906.png",200,270,false],"thumbnail":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-e1676727439906-150x150.png",150,150,true],"medium":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-e1676727064311-222x300.png",222,300,true],"medium_large":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-768x1037.png",768,1037,true],"large":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-758x1024.png",758,1024,true],"1536x1536":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-e1676727439906.png",200,270,false],"2048x2048":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2023\/02\/Runonce-e1676727439906.png",200,270,false]},"uagb_author_info":{"display_name":"Sandeep","author_link":"https:\/\/thecloudwiki.com\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":"Introduction Run Once is an optional component while creating an [&hellip;]","_links":{"self":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1693"}],"version-history":[{"count":3,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1693\/revisions"}],"predecessor-version":[{"id":1699,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1693\/revisions\/1699"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/media\/1694"}],"wp:attachment":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}