{"id":1122,"date":"2022-10-14T09:08:36","date_gmt":"2022-10-14T01:08:36","guid":{"rendered":"https:\/\/benson.ml\/?p=1122"},"modified":"2022-10-14T09:10:11","modified_gmt":"2022-10-14T01:10:11","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8windows-10%e5%90%af%e5%8a%a8%e6%97%b6%e8%87%aa%e5%8a%a8%e8%a3%85%e8%bd%bdvhdpowershell","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=1122","title":{"rendered":"\u5982\u4f55\u5728Windows 10\u542f\u52a8\u65f6\u81ea\u52a8\u88c5\u8f7dVHD(PowerShell)"},"content":{"rendered":"\n<p>\u6b64 PowerShell \u811a\u672c\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u5728 Windows 10\u542f\u52a8\u65f6\u81ea\u52a8\u88c5\u8f7d VHD\u3002<\/p>\n\n\n\n<p>\u7528\u6237\u91cd\u542f\u8ba1\u7b97\u673a\u65f6\uff0c\u9700\u8981\u91cd\u65b0\u88c5\u8f7d\u6240\u6709\u5df2\u88c5\u8f7d\u7684 VHD \u6587\u4ef6\u3002\u4ee5\u4e0b\u811a\u672c\u7528\u4e8e\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u6b65\u9aa4 1\uff1a\u53f3\u952e\u5355\u51fb PowerShell\uff0c\u7136\u540e\u9009\u62e9\u201c\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u201d\u3002<\/p>\n\n\n\n<p>\u6b65\u9aa4 2\uff1a\u7136\u540e\uff0c\u5c06\u6b64\u811a\u672c\u62d6\u52a8\u5230 PowerShell \u63a7\u5236\u53f0\u5e76\u8f93\u5165\u5982\u4e0b\u6240\u793a\u7684\u547d\u4ee4\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"198\" src=\"https:\/\/benson.ml\/wp-content\/uploads\/2022\/10\/image-12.png\" alt=\"\" class=\"wp-image-1124\" srcset=\"https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/10\/image-12.png 658w, https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/10\/image-12-300x90.png 300w, https:\/\/benson80.eu.org\/wp-content\/uploads\/2022\/10\/image-12-421x127.png 421w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><figcaption>\u6ce8\u610f<br>\u5982\u679c\u4f60\u4e0d\u5e0c\u671b\u5728\u542f\u52a8\u65f6\u88c5\u8f7d VHD \u6587\u4ef6\uff0c\u5219\u53ef\u4ee5\u8fd0\u884c schtasks\uff0c\u627e\u5230\u8ba1\u5212\u4efb\u52a1 MountVHD\uff0c\u7136\u540e\u5c06\u5176\u5220\u9664\u3002<br>\u5982\u679c VHD \u6587\u4ef6\u5c1a\u672a\u6267\u884c\u201c\u521d\u59cb\u5316\u78c1\u76d8\u201d\u6216\u201c\u65b0\u5efa\u7b80\u5355\u5377\u201d\u64cd\u4f5c\uff0c\u5219\u65e0\u6cd5\u901a\u8fc7 Windows \u78c1\u76d8\u9a71\u52a8\u5668\u67e5\u770b\u8be5 VHD\u3002\u82e5\u8981\u4e86\u89e3\u5982\u4f55\u6267\u884c\u201c\u521d\u59cb\u5316\u78c1\u76d8\u201d\u548c\u201c\u65b0\u5efa\u7b80\u5355\u5377\u201d\u64cd\u4f5c\uff0c\u8bf7\u67e5\u770b\u4ee5\u4e0b\u6587\u6863\u4f5c\u4e3a\u53c2\u8003\uff1a<\/figcaption><\/figure>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-R2-and-2008\/cc771486(v=ws.11)?redirectedfrom=MSDN\" target=\"_blank\">\u521d\u59cb\u5316\u78c1\u76d8<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/technet.microsoft.com\/zh-cn\/magazine\/gg309170.aspx\" target=\"_blank\">\u65b0\u5efa\u7b80\u5355\u5377<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>param\n(\n    &#91;Parameter(Mandatory=$true)]\n    &#91;String]$Path\n)\n\nif(test-path -Path $path)\n{\n    \n    #Create diskpart configuration file\n    $content = \"select vdisk file= `\"$path`\"`nattach vdisk\" \n    #Output the file and store the file into user profile folder\n    out-file -InputObject $content -FilePath \"$env:USERPROFILE\\MountVHD.txt\" -Encoding ascii -Force \n    #Add schedule task\n    schtasks \/create \/tn \"MountVHD\" \/tr \"diskpart.exe \/s '$env:USERPROFILE\\MountVHD.txt'\" \/sc ONLOGON \/ru SYSTEM\n\n    write-host \"Operation executed successfully. The specified VHD file will be mounted next logon.\"\n}\nElse\n{\n    Write-Warning \"The path is invalid.\"\n}<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/How-to-automatically-mount-d623ce34\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/gallery.technet.microsoft.com\/scriptcenter\/How-to-automatically-mount-d623ce34<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b64 PowerShell \u811a\u672c\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u5728 Wi &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1122","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1122"}],"version-history":[{"count":2,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1122\/revisions"}],"predecessor-version":[{"id":1125,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1122\/revisions\/1125"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}