{"id":1006,"date":"2011-10-24T14:38:00","date_gmt":"2011-10-24T14:38:00","guid":{"rendered":"http:\/\/www.obieta.com\/?p=1006"},"modified":"2011-10-24T14:38:00","modified_gmt":"2011-10-24T14:38:00","slug":"automatically-attach-a-vhd-in-windows-server-2008-r2-during-startup","status":"publish","type":"post","link":"https:\/\/obieta.com\/?p=1006","title":{"rendered":"Automatically ATTACH A .VHD IN WINDOWS SERVER 2008 R2 during Startup"},"content":{"rendered":"<p>Windows Server 2008 R2 (and Windows 7) has the ability to create and attach VHDs directly from Disk Management. Unfortunately they detach if your server reboots. This can be fixed with a little scripting.<\/p>\n<p>Open the Group Policy Object Editor mmc Snap-in and drill down to Local Computer Policy -&gt; Computer Configuration -&gt; Windows Settings -&gt; Scripts -&gt; Startup.<\/p>\n<p>Create two new scripts. The first script is a diskpart script to actually mount your VHD file. Call it step1.txt.<\/p>\n<p>select vdisk file=\u201dc:mydisk.vhd\u201d<br \/>attach vdisk<\/p>\n<p>The second script is a .cmd script that just runs diskpart with the \/s switch and passes in your diskpart script file. Call it AttachVHD.cmd<\/p>\n<p>diskpart \/s step1.txt<\/p>\n<p>Set the AttachVHD.cmd as a Startup script in the Group Policy Object snap-in.<\/p>\n<p>Windows will now automatically attach your .vhd when your system reboots.<\/p>\n<div>Assign computer startup scripts<\/div>\n<p>Updated: January 21, 2005<\/p>\n<p>Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2<\/p>\n<div id=\"mainSection\">\n<div id=\"mainBody\">\n<p>&nbsp;<\/p>\n<h2>To assign computer startup scripts<\/h2>\n<div id=\"sectionSection0\">\n<ol>\n<li>Open Group Policy Object Editor. <\/li>\n<li>In the console tree, click\u00a0<strong>Scripts (Startup\/Shutdown)<\/strong>.\n<p><strong>Where?<\/strong><\/p>\n<ul>\n<li><em>Group Policy object<\/em>\/Computer Configuration\/Windows Settings\/Scripts (Startup\/Shutdown) <\/li>\n<\/ul>\n<\/li>\n<li>In the details pane, double-click\u00a0<strong>Startup<\/strong>. <\/li>\n<li>In the\u00a0<strong>Startup Properties<\/strong> dialog box, click\u00a0<strong>Add<\/strong>. <\/li>\n<li>In the\u00a0<strong>Add a Script<\/strong> dialog box, do the following:\n<ul>\n<li>In\u00a0<strong>Script Name<\/strong>, type the path to the script, or click\u00a0<strong>Browse<\/strong> to search for the script file in the Netlogon shared folder on the domain controller. <\/li>\n<li>In\u00a0<strong>Script Parameters<\/strong>, type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called \/\/logo (display banner) and \/\/I (interactive mode), type\u00a0<strong>\/\/logo \/\/I<\/strong>. <\/li>\n<\/ul>\n<\/li>\n<li>In the\u00a0<strong>Startup Properties<\/strong> dialog box, specify the options that you want as follows:\n<ul>\n<li><strong>Startup Scripts for <\/strong><strong><em>Group Policy object<\/em><\/strong><strong>&#8212;<\/strong>Lists all the scripts that are currently assigned to the selected Group Policy object. If you assign multiple scripts, the scripts are processed in the order that you specify. To move a script up in the list, click it, and then click\u00a0<strong>Up<\/strong>. To move a script down in the list, click it, and then click\u00a0<strong>Down<\/strong>. <\/li>\n<li><strong>Add&#8211;<\/strong>Opens the\u00a0<strong>Add a Script<\/strong> dialog box, where you can specify any additional scripts to use. <\/li>\n<li><strong>Edit&#8211;<\/strong>Opens the\u00a0<strong>Edit Script<\/strong> dialog box, where you can modify script information, such as name and parameters. <\/li>\n<li><strong>Remove&#8211;<\/strong>Removes the selected script from the\u00a0<strong>Startup Scripts<\/strong> list. <\/li>\n<li><strong>Show Files&#8211;<\/strong>Displays the script files that are stored in the selected Group Policy object.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Windows Server 2008 R2 (and Windows 7) has the ability to create and attach VHDs directly from Disk Management. Unfortunately they detach if your server reboots. This can be fixed with a little scripting. Open the Group Policy Object Editor mmc Snap-in and drill down to Local Computer Policy -&gt; Computer Configuration -&gt; Windows Settings [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,7],"tags":[],"_links":{"self":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1006"}],"collection":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1006"}],"version-history":[{"count":0,"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1006\/revisions"}],"wp:attachment":[{"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}