{"id":3740,"date":"2016-09-15T13:19:18","date_gmt":"2016-09-15T04:19:18","guid":{"rendered":"http:\/\/www.syuheiuda.com\/?p=3740"},"modified":"2016-09-15T13:19:18","modified_gmt":"2016-09-15T04:19:18","slug":"powershell-direct-%e3%81%a7-vm-%e5%b1%95%e9%96%8b%e3%82%92%e8%87%aa%e5%8b%95%e5%8c%96%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.syuheiuda.com\/?p=3740","title":{"rendered":"PowerShell Direct \u3067 VM \u5c55\u958b\u3092\u81ea\u52d5\u5316\u3057\u3066\u307f\u308b"},"content":{"rendered":"<p>Windows 10 \/ Windows Server 2016 \u304b\u3089\u3001PowerShell Direct \u3068\u3044\u3046\u6a5f\u80fd\u304c\u5897\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u6d3b\u7528\u3059\u308b\u3068\u3001Hyper-V \u30db\u30b9\u30c8\u304b\u3089 VM \u306e\u4e2d\u306b\u5bfe\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3057\u305f\u308a\u3001\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u304c\u3067\u304d\u308b\u306e\u3067\u3001\u5927\u91cf\u306e VM \u3092\u81ea\u52d5\u3067\u5c55\u958b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001Azure PowerShell \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u6bce\u306b VM \u3092\u4f5c\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3002<\/p>\n<p>\u4e8b\u524d\u306b\u5fdc\u7b54\u30d5\u30a1\u30a4\u30eb\u3092\u5dee\u3057\u8fbc\u3093\u3060 sysprep \u6e08\u307f\u306e VHD \u3068\u3001\u5404\u30d0\u30fc\u30b8\u30e7\u30f3\u306e Azure PowerShell \u3092\u7528\u610f\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u305d\u306e\u8fba\u306f\u8aac\u660e\u304c\u9577\u304f\u306a\u308b\u306e\u3067\u4eca\u56de\u306f\u66f8\u304d\u307e\u305b\u3093\u3002(\u308f\u304b\u3089\u306a\u3044\u4eba\u306f\u3001\u5fdc\u7b54\u30d5\u30a1\u30a4\u30eb\u3068\u304b unattend \u3068\u304b sysprep \u3068\u3044\u3063\u305f\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u691c\u7d22\u3059\u308c\u3070\u3044\u304f\u3089\u3067\u3082\u60c5\u5831\u3067\u308b\u306e\u3067\u8abf\u3079\u3066\u304f\u3060\u3055\u3044\u3002)<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n# Azure PowerShell \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3092\u914d\u7f6e\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u30fc\r\n$PowerShellInstallder = Get-ChildItem 'C:\\Users\\Administrator\\Desktop\\Azure PowerShell'\r\n\r\n# Azure PowerShell \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u5206\u3060\u3051 VM \u3092\u4f5c\u6210\r\n$PowerShellInstallder | foreach{\r\n    # \u30d5\u30a1\u30a4\u30eb\u540d (azure-powershell.1.0.0.msi) \u304b\u3089\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u62bd\u51fa\r\n    $Ver = $_.Name -replace 'azure-powershell.', '' -replace '.msi', ''\r\n\r\n    # \u4eee\u60f3\u30de\u30b7\u30f3\u540d\u306e Prefix \u3092\u5b9a\u7fa9\r\n    $VMName = 'Win 10 Ent x64 with Azure PowerShell $Ver'\r\n\r\n    # sysprep \u6e08\u307f\u306e\u30de\u30b9\u30bf\u30fc \u30a4\u30e1\u30fc\u30b8\u3092\u30b3\u30d4\u30fc\r\n    Copy-Item -Path 'D:\\Win 10 Ent x64 with Azure PowerShell Master.vhdx' -Destination 'D:\\Win 10 Ent x64 with Azure PowerShell $Ver.vhdx'\r\n\r\n    # \u30b3\u30d4\u30fc\u3057\u305f VHD \u3092\u3082\u3068\u306b VM \u3092\u4f5c\u6210\r\n    New-VM -Name $VMName -VHDPath 'D:\\Win 10 Ent x64 with Azure PowerShell $Ver.vhdx'\r\n\r\n    # VM \u306e\u30b3\u30a2\u6570\u3001\u30e1\u30e2\u30ea\u3001NIC \u306a\u3069\u3092\u4efb\u610f\u3067\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\r\n    Set-VMProcessor -VMName $VMName -Count 16\r\n    Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $true\r\n    Set-VMNetworkAdapter -VMName $VMName\r\n    Get-VMNetworkAdapter -VMName $VMName | Connect-VMNetworkAdapter -SwitchName external\r\n\r\n    # VM \u3092\u8d77\u52d5\r\n    Start-VM -Name $VMName\r\n}\r\n<\/pre>\n<p>\u4e0a\u8a18\u306f\u7a7a\u306e VM \u3092\u4f5c\u3063\u305f\u3060\u3051\u306a\u306e\u3067\u3001\u7d9a\u3044\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3092 VM \u5185\u306b\u30b3\u30d4\u30fc\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n\u3042\u308f\u305b\u3066\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067 Windows PowerShell \u306e Execution Policy \u3068\u304b\u3001Explorer \u306e\u30ec\u30b8\u30b9\u30c8\u30ea\u3082\u4e00\u7dd2\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$PowerShellInstallder | foreach{\r\n    # \u5404\u7a2e\u5909\u6570\u3092\u8a2d\u5b9a\r\n    $FullPath = $_.FullName\r\n    $FileName = $_.Name\r\n    $Ver = $_.Name -replace 'azure-powershell.', '' -replace '.msi', ''\r\n    $VMName = 'Win 10 Ent x64 with Azure PowerShell $Ver'\r\n    $InstallerPath = 'C:\\Users\\Public\\Documents\\$FileName'\r\n\r\n    # \u65b0\u898f\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u78ba\u7acb\r\n    $Session = New-PSSession -VMName $VMName -Credential $Cred\r\n\r\n    # VM \u5185\u3067\u5b9f\u884c\u3059\u308b\u51e6\u7406\u306e\u5b9a\u7fa9\r\n    $DeployScript = '\r\n    reg add HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced \/v LaunchTo \/t REG_DWORD \/d 1 \/f\r\n    reg add HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer \/v ShowRecent \/t REG_DWORD \/d 0 \/f\r\n    reg add HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer \/v ShowFrequent \/t REG_DWORD \/d 0 \/f\r\n    reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced \/v HideFileExt \/t REG_DWORD \/d 0 \/f\r\n    reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced \/v Hidden \/t REG_DWORD \/d 1 \/f\r\n    reg add HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell \/v EnableScripts \/t REG_DWORD \/d 1 \/f\r\n    reg add HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\PowerShell \/v ExecutionPolicy \/t REG_SZ \/d RemoteSigned \/f\r\n    Start-Process -FilePath $InstallerPath -ArgumentList '\/quiet' # Azure PowerShell \u306e\u30b5\u30a4\u30ec\u30f3\u30c8 \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\n    '\r\n\r\n    # \u4e0a\u8a18\u3067\u5b9a\u7fa9\u3057\u305f\u5185\u5bb9\u3092\u3001\u4e00\u65e6\u30ed\u30fc\u30ab\u30eb\u306b\u4fdd\u5b58\r\n    Out-File -InputObject $DeployScript -FilePath $env:TEMP\\deploy.ps1\r\n\r\n    # VM \u5185\u306b Azure PowrShell \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u30fc\u3092\u30b3\u30d4\u30fc\r\n    Copy-Item -ToSession $Session -Path $FullPath -Destination 'C:\\Users\\Public\\Documents'\r\n\r\n    # VM \u5185\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u51e6\u7406\u3092\u5b9f\u884c\r\n    Invoke-Command -VMName $VMName -Credential $Cred $env:TEMP\\deploy.ps1\r\n}\r\n<\/pre>\n<p>\u4ee5\u4e0a\u3067\u5404\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u305f VM \u304c\u5927\u91cf\u306b\u751f\u6210\u3055\u308c\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3082\u5b8c\u4e86\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\nVHD \u306e\u30b3\u30d4\u30fc\u306b\u306f\u7d50\u69cb\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u3001NVMe SSD \u3068\u304b\u3092\u4f7f\u3046\u3068\u5feb\u9069\u3067\u3059\u306d\u3002<\/p>\n<p><a href=\"https:\/\/blob.syuheiuda.com\/wp-content\/2016\/09\/vmms.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blob.syuheiuda.com\/wp-content\/2016\/09\/vmms.png\" alt=\"vmms\" width=\"941\" height=\"489\" class=\"alignnone size-full wp-image-3748\" srcset=\"\/wp-content\/uploads\/2016\/09\/vmms.png 941w, \/wp-content\/uploads\/2016\/09\/vmms-300x156.png 300w, \/wp-content\/uploads\/2016\/09\/vmms-768x399.png 768w, \/wp-content\/uploads\/2016\/09\/vmms-560x291.png 560w, \/wp-content\/uploads\/2016\/09\/vmms-260x135.png 260w, \/wp-content\/uploads\/2016\/09\/vmms-160x83.png 160w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/blob.syuheiuda.com\/wp-content\/2016\/09\/vm.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blob.syuheiuda.com\/wp-content\/2016\/09\/vm-1024x768.png\" alt=\"vm\" width=\"860\" height=\"645\" class=\"alignnone size-large wp-image-3747\" srcset=\"\/wp-content\/uploads\/2016\/09\/vm.png 1024w, \/wp-content\/uploads\/2016\/09\/vm-300x225.png 300w, \/wp-content\/uploads\/2016\/09\/vm-768x576.png 768w, \/wp-content\/uploads\/2016\/09\/vm-560x420.png 560w, \/wp-content\/uploads\/2016\/09\/vm-260x195.png 260w, \/wp-content\/uploads\/2016\/09\/vm-160x120.png 160w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows 10 \/ Windows Server 2016 \u304b\u3089\u3001Powe&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/www.syuheiuda.com\/?p=3740\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_locale":"","_original_post":""},"categories":[39,37,31,7,9,38],"tags":[],"views":6021,"_links":{"self":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/3740"}],"collection":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3740"}],"version-history":[{"count":8,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/3740\/revisions"}],"predecessor-version":[{"id":3750,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/3740\/revisions\/3750"}],"wp:attachment":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}