{"id":2918,"date":"2023-02-27T10:00:00","date_gmt":"2023-02-27T01:00:00","guid":{"rendered":"https:\/\/www.itc109.com\/knowledge\/?p=2918"},"modified":"2023-09-03T03:07:33","modified_gmt":"2023-09-02T18:07:33","slug":"azure-powershell%e3%81%a7%e3%83%8d%e3%83%83%e3%83%88%e3%83%af%e3%83%bc%e3%82%af%e3%82%a4%e3%83%b3%e3%82%bf%e3%83%bc%e3%83%95%e3%82%a7%e3%83%bc%e3%82%b9%e3%81%ae%e4%bd%9c%e6%88%90","status":"publish","type":"post","link":"https:\/\/www.itc109.com\/knowledge\/powershell\/azure-powershell%e3%81%a7%e3%83%8d%e3%83%83%e3%83%88%e3%83%af%e3%83%bc%e3%82%af%e3%82%a4%e3%83%b3%e3%82%bf%e3%83%bc%e3%83%95%e3%82%a7%e3%83%bc%e3%82%b9%e3%81%ae%e4%bd%9c%e6%88%90","title":{"rendered":"Azure &#8211; PowerShell\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u4f5c\u6210"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>AWS\u3092\u30e1\u30a4\u30f3\u3067\u5229\u7528\u3057\u3066\u3044\u308b\u30a8\u30f3\u30b8\u30cb\u30a2\u304cAzure\u74b0\u5883\u306e\u69cb\u7bc9\u3092PowerShell\u3067\u9032\u3081\u308b\u9023\u8f09\u3002<br>\n\u30ea\u30bd\u30fc\u30b9\u30b0\u30eb\u30fc\u30d7\u306e\u4f5c\u6210\u304b\u3089\u4eee\u60f3\u30de\u30b7\u30f3\u3092\u8d77\u52d5\u3059\u308b\u307e\u3067\u3092\u9023\u8f09\u3057\u3066\u3044\u304f\u4e88\u5b9a\u3067\u3059\u3002<\/p>\n<p>\u7b2c6\u56de\u306f\u3001\u3053\u308c\u304b\u3089\u4f5c\u6210\u3059\u308b\u4eee\u60f3\u30de\u30b7\u30f3\u306b\u30a2\u30bf\u30c3\u30c1\u3059\u308b\u3001AWS\u3067\u8a00\u3046\u3068\u3053\u308d\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u985e\u4f3c\u3059\u308b\u30b5\u30fc\u30d3\u30b9\u300c\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u300d\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/www.itc109.com\/knowledge\/?p=2800\">\u7b2c01\u56de PowerShell\u3067Azure\u306b\u63a5\u7d9a<\/a><\/li>\n<li><a href=\"https:\/\/www.itc109.com\/knowledge\/?p=2836\">\u7b2c02\u56de PowerShell\u3067\u30ea\u30bd\u30fc\u30b9\u30b0\u30eb\u30fc\u30d7\u306e\u4f5c\u6210<\/a><\/li>\n<li><a href=\"https:\/\/www.itc109.com\/knowledge\/?p=2863\">\u7b2c03\u56de PowerShell\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7\u306e\u4f5c\u6210<\/a><\/li>\n<li><a href=\"https:\/\/www.itc109.com\/knowledge\/?p=3042\">\u7b2c04\u56de PowerShell\u3067\u53d7\u4fe1\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u898f\u5247\u306e\u8ffd\u52a0<\/a><\/li>\n<li><a href=\"https:\/\/www.itc109.com\/knowledge\/?p=2851\">\u7b2c05\u56de PowerShell\u3067\u4eee\u60f3\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u4f5c\u6210<\/a><\/li>\n<li>\u7b2c06\u56de PowerShell\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u4f5c\u6210\u3000\u2190\u2605\u3053\u3053<\/li>\n<li>\u7b2c07\u56de PowerShell\u3067\u30d1\u30d6\u30ea\u30c3\u30afIP\u30a2\u30c9\u30ec\u30b9\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c08\u56de PowerShell\u3067\u4eee\u60f3\u30de\u30b7\u30f3\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c09\u56de PowerShell\u3067\u30ea\u30bd\u30fc\u30b9\u306e\u30ed\u30c3\u30af<\/li>\n<\/ul>\n<p>\u756a\u5916\u7de8<\/p>\n<ul>\n<li>\u7b2c10\u56de PowerShell\u3067\u30b9\u30c8\u30ec\u30fc\u30b8\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c11\u56de PowerShell\u3067\u4eee\u60f3\u30de\u30b7\u30f3\u7528VHD\u30a4\u30e1\u30fc\u30b8\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9<\/li>\n<li>\u7b2c12\u56de PowerShell\u3067\u4eee\u60f3\u30de\u30b7\u30f3\u3092VHD\u30a4\u30e1\u30fc\u30b8\u304b\u3089\u4f5c\u6210<\/li>\n<li>\u7b2c13\u56de PowerShell\u3067\u30c7\u30a3\u30b9\u30af\u306e\u62e1\u5f35<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u624b\u9806<\/h2>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u524d\u63d0\uff1a\u4e8b\u524d\u306b\u300c<a href=\"https:\/\/www.itc109.com\/knowledge\/?p=2851\">\u4eee\u60f3\u30cd\u30c3\u30c8\u30ef\u30fc\u30af<\/a>\u300d\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code># \u30ea\u30bd\u30fc\u30b9\u30b0\u30eb\u30fc\u30d7\u540d\u3092\u8a2d\u5b9a\n$private:resourceGroupName = &quot;rg001&quot;\n\n# \u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a\n$private:location = &quot;japaneast&quot;\n\n# \u30bf\u30b0\u3092\u8a2d\u5b9a\n$tags = @{&quot;\u74b0\u5883\u540d&quot;=&quot;ITC109&quot;}\n\n# \u4eee\u60f3\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u540d\u3092\u8a2d\u5b9a\n$private:vnwName = $private:resourceGroupName + &quot;vnw&quot;\n\n# \u4eee\u60f3\u30de\u30b7\u30f3\u540d\u3092\u8a2d\u5b9a\n$private:vmname = $private:resourceGroupName + &quot;vm01&quot;<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code># \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u540d\u3092\u8a2d\u5b9a\n$private:nicname = $private:vmname + &quot;nwif&quot;\n\n$private:nics = Get-AzNetworkInterface -ResourceGroupName $private:resourceGroupName -Name $private:nicname -ErrorAction Ignore -WarningAction Ignore\nif (-not $private:nics) {\n    try{\n        # \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u4f5c\u6210(\u30d1\u30d6\u30ea\u30c3\u30af\u30b5\u30d6\u30cd\u30c3\u30c8\u306b\u4f5c\u6210)\n        $private:subnet = (Get-AzVirtualNetwork -ResourceGroupName $private:resoucreGroupName -Name $private:vnwName -WarningAction Ignore).Subnets | Where-Object {$_.Name -eq &quot;publicSubnet&quot;}\n\n        # \u5bfe\u8c61\u306e\u30b5\u30d6\u30cd\u30c3\u30c8\u306e\u6709\u7121\n        if ($private:subnet) {\n            # \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\n            Write-Host (&quot;${private:resourceGroupName} \u306e\u300c\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u300d\u306b ${private:nicname} \u3092\u4f5c\u6210\u4e2d...&quot;)\n            $private:nic = New-AzNetworkInterface -Location $private:location -ResourceGroupName $private:resourceGroupName -Name $private:nicname -Subnet $private:subnet -Tag $tags -ErrorAction Stop\n            Write-Host (&quot;${private:resourceGroupName} \u306e\u300c\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u300d\u306b ${private:nicname} \u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002&quot;)\n            Write-Host &quot;&quot;\n\n            # \u30d7\u30e9\u30a4\u30d9\u30fc\u30c8IP\u30a2\u30c9\u30ec\u30b9\u3092\u56fa\u5b9a\n            $private:nic.IpConfigurations[0].PrivateIpAllocationMethod = &#39;Static&#39;\n            $null = Set-AzNetworkInterface -NetworkInterface $private:nic -ErrorAction Stop\n            Write-Host (&quot;\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8IP\u30a2\u30c9\u30ec\u30b9\u3092\u9759\u7684\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002&quot;)\n            Write-Host &quot;&quot;\n\n        } else {\n            # \u30b5\u30d6\u30cd\u30c3\u30c8\u304c\u5b58\u5728\u3057\u306a\u3044\n            Write-Host &quot;\u6307\u5b9a\u306e\u30b5\u30d6\u30cd\u30c3\u30c8\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u3002&quot; -ForegroundColor Red\n            Write-Host &quot;&quot;\n        }\n\n    } catch {\n        Write-Host &quot;\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u4f5c\u6210 or \u30d7\u30e9\u30a4\u30d9\u30fc\u30c8IP\u30a2\u30c9\u30ec\u30b9\u56fa\u5b9a\u30a8\u30e9\u30fc&quot; -ForegroundColor Red\n        Write-Error -Message $_.Exception\n        Write-Host &quot;&quot;\n\n    }\n\n} else {\n    Write-Host (&quot;${private:resourceGroupName} \u306e\u300c\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u300d\u306b\u306f\u3001\u65e2\u306b ${private:nicname} \u304c\u5b58\u5728\u3059\u308b\u305f\u3081\u4f5c\u6210\u3092\u30b9\u30ad\u30c3\u30d7\u3057\u307e\u3057\u305f\u3002&quot;) -ForegroundColor Yellow\n    Write-Host &quot;&quot;\n\n}\n\n##################################################\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p><code>Get-AzNetworkInterface<\/code>\u3067\u65e2\u306b\u540c\u540d\u306e\u30ea\u30bd\u30fc\u30b9\u304c\u5b58\u5728\u3057\u306a\u3044\u304b\u78ba\u8a8d\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$private:vnw = Get-AzNetworkInterface -ResourceGroupName $private:resourceGroupName -Name $private:nicname\n\nif (-not $private:nics) {\n  \u203b\u30ea\u30bd\u30fc\u30b9\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u3001\u3053\u3053\u306b\u4f5c\u6210\u3059\u308b\u51e6\u7406\u3092\u8a18\u8ff0\u3002\n} else {\n  \u203b\u30ea\u30bd\u30fc\u30b9\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u3053\u3053\u306b\u4f5c\u6210\u3057\u306a\u3044\u51e6\u7406\u3092\u8a18\u8ff0\u3002\n}<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p><code>New-AzNetworkInterface<\/code>\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$private:nic = New-AzNetworkInterface -Location $private:location -ResourceGroupName $private:resourceGroupName -Name $private:nicname -Subnet $private:subnet -Tag $tags -ErrorAction Stop<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p><code>-Subnet<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u300c\u30b5\u30d6\u30cd\u30c3\u30c8\u300d\u306b\u3064\u3044\u3066\u5229\u7528\u53ef\u80fd\u306a\u30b5\u30d6\u30cd\u30c3\u30c8\u3092\u6307\u5b9a\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>-Subnet $private:subnet<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u30b5\u30d6\u30cd\u30c3\u30c8\u306e\u4e00\u89a7\u304b\u3089\u300cpublicSubnet\u300d\u3092\u6307\u5b9a\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$private:subnet = (Get-AzVirtualNetwork -ResourceGroupName $private:resourceGroupName -Name $private:vnwName).Subnets | Where-Object {$_.Name -eq &quot;publicSubnet&quot;}<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u300cprivateSubnet\u300d\u306b\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u3001\u6307\u5b9a\u3092\u5909\u66f4\u3059\u308b\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$private:subnet = (Get-AzVirtualNetwork -ResourceGroupName $private:resourceGroupName -Name $private:vnwName).Subnets | Where-Object {$_.Name -eq &quot;privateSubnet&quot;}<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p><code>try \uff5e catch<\/code>\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>try {\n    \u203b\u30ea\u30bd\u30fc\u30b9\u306e\u4f5c\u6210\u306e\u4f5c\u6210\u3002\n} catch {\n    \u203b\u30ea\u30bd\u30fc\u30b9\u306e\u4f5c\u6210\u306e\u4f5c\u6210\u306b\u5931\u6557\u3002\n    Write-Error -Message $_.Exception\n}<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30ea\u30bd\u30fc\u30b9 \u30d3\u30b8\u30e5\u30a2\u30e9\u30a4\u30b6\u30fc<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-1024x576.png\" alt=\"\" class=\"wp-image-3081\" srcset=\"https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-1024x576.png 1024w, https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-300x169.png 300w, https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-768x432.png 768w, https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-1536x864.png 1536w, https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9-2048x1151.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u624b\u9806 \u30ea\u30bd\u30fc\u30b9 \u30d3\u30b8\u30e5\u30a2\u30e9\u30a4\u30b6\u30fc<\/p>\n","protected":false},"author":3,"featured_media":2808,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[125,81],"tags":[75],"class_list":["post-2918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-powershell","tag-powershell"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.itc109.com\/knowledge\/wp-content\/uploads\/sites\/2\/Azure.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pacZwp-L4","_links":{"self":[{"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/comments?post=2918"}],"version-history":[{"count":22,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2918\/revisions"}],"predecessor-version":[{"id":3167,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2918\/revisions\/3167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/media\/2808"}],"wp:attachment":[{"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/media?parent=2918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/categories?post=2918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/tags?post=2918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}