{"id":2800,"date":"2023-01-23T10:00:00","date_gmt":"2023-01-23T01:00:00","guid":{"rendered":"https:\/\/www.itc109.com\/knowledge\/?p=2800"},"modified":"2023-03-01T14:06:24","modified_gmt":"2023-03-01T05:06:24","slug":"azure-powershell%e3%81%a7azure%e3%81%ab%e6%8e%a5%e7%b6%9a","status":"publish","type":"post","link":"https:\/\/www.itc109.com\/knowledge\/powershell\/azure-powershell%e3%81%a7azure%e3%81%ab%e6%8e%a5%e7%b6%9a","title":{"rendered":"Azure &#8211; PowerShell\u3067Azure\u306b\u63a5\u7d9a"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6982\u8981<\/h2>\n\n\n\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\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>\u7b2c1\u56de\u306f\u3001\u4f55\u306f\u3068\u3082\u3042\u308c\u307e\u305a\u306fPowerShell\u3067Azure\u306b\u63a5\u7d9a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u7b2c01\u56de PowerShell\u3067Azure\u306b\u63a5\u7d9a\u3000\u2190\u2605\u3053\u3053<\/li>\n<li>\u7b2c02\u56de PowerShell\u3067\u30ea\u30bd\u30fc\u30b9\u30b0\u30eb\u30fc\u30d7\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c03\u56de PowerShell\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c04\u56de PowerShell\u3067\u53d7\u4fe1\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u898f\u5247\u306e\u8ffd\u52a0<\/li>\n<li>\u7b2c05\u56de PowerShell\u3067\u4eee\u60f3\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u4f5c\u6210<\/li>\n<li>\u7b2c06\u56de PowerShell\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u4f5c\u6210<\/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=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code># \u30c6\u30ca\u30f3\u30c8ID\u3092\u6307\u5b9a \n$script:tenantId = &quot;xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx&quot;\n\n# \u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3ID\u3092\u6307\u5b9a\n$script:subscriptionId = &quot;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&quot;\n\n##################################################\nWrite-Host &quot;\u25a0\u25a0 Azure\u3078\u306e\u63a5\u7d9a\u51e6\u7406 \u25a0\u25a0&quot;\n##################################################\n# \u8a8d\u8a3c\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30af\u30ea\u30a2 \nClear-AzContext -Force \n\nWrite-Host &quot;Azure\u306b\u63a5\u7d9a\u4e2d...&quot;\n$script:cn = Connect-AzAccount -Tenant $script:tenantId -SubscriptionId $script:subscriptionId\n\n# \u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u306e\u78ba\u8a8d \nif (-not $script:cn) {\n  Write-Host &quot;Azure\u3078\u306e\u63a5\u7d9a\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3057\u305f\u3002&quot; -ForegroundColor Red\n  Write-Host &quot;&quot;\n\n  # \u30ed\u30e1\u30b0\u30a4\u30f3\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\u969b\u306e\u51e6\u7406\u3092\u8a18\u8ff0\n  exit\n\n} else {\n  Write-Host &quot;Azure\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f\u3002&quot;\n  Write-Host &quot;&quot;\n\n}\n##################################################\n# \u3053\u308c\u3088\u308a\u5148\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u969b\u306e\u51e6\u7406\u3092\u8a18\u8ff0<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u8907\u6570\u306e\u30c6\u30ca\u30f3\u30c8\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u8aa4\u3063\u3066\u4ed6\u306e\u30c6\u30ca\u30f3\u30c8\u3092\u64cd\u4f5c\u3057\u306a\u3044\u3088\u3046\u306b\u3001\u8a8d\u8a3c\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30af\u30ea\u30a2\u3057\u3066\u304a\u304f\u3053\u3068\u3092\u63a8\u5968\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>Clear-AzContext -Force<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>Azure\u306b\u5bfe\u8a71\u578b\u3067\u63a5\u7d9a\u3059\u308b\u969b\u306f\u3001<code>Connect-AzAccount<\/code> \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>Connect-AzAccount<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u30c6\u30ca\u30f3\u30c8\u3092\u6307\u5b9a\u3057\u3066Azure\u306b\u63a5\u7d9a\u3059\u308b\u5834\u5408\u306f\u3001 <code>-Tenant<\/code>  \u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u30c6\u30ca\u30f3\u30c8ID\u3068 <code>-SubscriptionId<\/code> \u3067\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3ID\u3092\u6307\u5b9a\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>Connect-AzAccount -Tenant $script:tenantId -SubscriptionId $script:subscriptionId<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u88dc\u8db3<\/h2>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><p>\u30ed\u30b0\u30a4\u30f3\u306b\u6210\u529f\u6642\u306e\u51e6\u7406\u3092IF\u3067\u51e6\u7406\u3059\u308b\u3088\u308a\u3001\u5931\u6557\u307e\u305f\u306f\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\u5834\u5408\u306b\u4e2d\u6b62\u3059\u308b\u51e6\u7406\u3092\u8a18\u8f09\u3057\u305f\u65b9\u304c\u3001\u5f8c\u306e\u69cb\u6587\u306e\u8a18\u8f09\u304c\u697d\u306b\u306a\u308b\u70ba\u3001\u6210\u529f\u6642\u306e\u51e6\u7406\u3068\u3057\u3066\u3044\u306a\u3044\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code># \u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u306e\u78ba\u8a8d \nif (-not $script:cn) {\n  Write-Host &quot;Azure\u3078\u306e\u63a5\u7d9a\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3057\u305f\u3002&quot; -ForegroundColor Red\n  Write-Host &quot;&quot;\n\n  # \u30ed\u30e1\u30b0\u30a4\u30f3\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\u969b\u306e\u51e6\u7406\u3092\u8a18\u8ff0\n  exit\n\n} else {\n  Write-Host &quot;Azure\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f\u3002&quot;\n  Write-Host &quot;&quot;\n\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u624b\u9806 \u88dc\u8db3<\/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":false,"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-2800","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-Ja","_links":{"self":[{"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2800","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=2800"}],"version-history":[{"count":26,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2800\/revisions"}],"predecessor-version":[{"id":3092,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/posts\/2800\/revisions\/3092"}],"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=2800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/categories?post=2800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itc109.com\/knowledge\/wp-json\/wp\/v2\/tags?post=2800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}