{"id":4251,"date":"2018-01-23T17:36:21","date_gmt":"2018-01-23T08:36:21","guid":{"rendered":"https:\/\/www.syuheiuda.com\/?p=4251"},"modified":"2019-03-08T12:24:04","modified_gmt":"2019-03-08T03:24:04","slug":"azure-powershell-%e3%81%a7-csv-%e3%81%8b%e3%82%89-nsg-%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.syuheiuda.com\/?p=4251","title":{"rendered":"Azure PowerShell \u3067 NSG \u3092 CSV \u306b\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u30fb\u30a4\u30f3\u30dd\u30fc\u30c8\u30fb\u8907\u88fd\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>NSG \u306b\u5927\u91cf\u306e\u30eb\u30fc\u30eb\u3092\u767b\u9332\u3059\u308b\u5834\u5408\u306a\u3069\u3001\u65e2\u5b58\u306e NSG \u306e\u8a2d\u5b9a\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u305f\u308a\u3001\u30b3\u30d4\u30fc\u3057\u305f\u308a\u3001CSV \u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u305f\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3088\u306d\u3002Azure PowerShell \u3067\u30b5\u30af\u3063\u3068\u3084\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n\n<p>CSV \u3078\u30a8\u30af\u30b9\u30dd\u30fc\u30c8<\/p>\n\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\"># \u65e2\u5b58\u306e NSG \u306e\u8a2d\u5b9a\u3092 CSV \u306b\u4fdd\u5b58\n(Get-AzureRmNetworkSecurityGroup -Name \"NSG \u540d\" -ResourceGroupName \"\u30ea\u30bd\u30fc\u30b9 \u30b0\u30eb\u30fc\u30d7\u540d\").SecurityRules | select `\n    Name, `\n    Description, `\n    Protocol, `\n    @{Name=\"SourcePortRange\"; Expression={$_.SourcePortRange -join \",\"}}, `\n    @{Name=\"DestinationPortRange\"; Expression={$_.DestinationPortRange -join \",\"}}, `\n    @{Name=\"SourceAddressPrefix\"; Expression={$_.SourceAddressPrefix -join \",\"}}, `\n    @{Name=\"DestinationAddressPrefix\"; Expression={$_.DestinationAddressPrefix -join \",\"}}, `\n    Access, `\n    Priority, `\n    Direction `\n| ConvertTo-Csv | select -Skip 1 | Out-File $Env:USERPROFILE\\Desktop\\nsg.csv -Encoding utf8<\/pre>\n<p>CSV \u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\"># \u65e2\u5b58\u306e NSG \u3092\u53d6\u5f97\n$NSG = Get-AzureRmNetworkSecurityGroup -Name \"NSG \u540d\" -ResourceGroupName \"\u30ea\u30bd\u30fc\u30b9 \u30b0\u30eb\u30fc\u30d7\u540d\"\n\n# \u3082\u3057\u304f\u306f\u7a7a\u306e NSG \u3092\u4f5c\u6210\n# $NSG = New-AzureRmNetworkSecurityGroup -Name \"NSG \u540d\" -ResourceGroupName \"\u30ea\u30bd\u30fc\u30b9 \u30b0\u30eb\u30fc\u30d7\u540d\" -Location \"\u30ea\u30fc\u30b8\u30e7\u30f3\u540d\"\n\n# CSV \u30d5\u30a1\u30a4\u30eb\u3092\u53d6\u5f97\n$CSV = Import-CSV \"CSV \u306e\u30d1\u30b9\" -Encoding UTF8\n\n# \u5404\u884c\u306e\u30eb\u30fc\u30eb\u3092\u8ffd\u52a0\n$CSV | foreach{\n    Add-AzureRmNetworkSecurityRuleConfig `\n    -Name $_.Name `\n    -NetworkSecurityGroup $NSG `\n    -Description $_.Description `\n    -Protocol $_.Protocol `\n    -SourcePortRange $_.SourcePortRange `\n    -DestinationPortRange $_.DestinationPortRange `\n    -SourceAddressPrefix ($_.SourceAddressPrefix  -split \",\") `\n    -DestinationAddressPrefix ($_.DestinationAddressPrefix  -split \",\") `\n    -Access $_.Access `\n    -Priority $_.Priority `\n    -Direction $_.Direction\n}\n\n# \u8a2d\u5b9a\u3092\u53cd\u6620\nSet-AzureRmNetworkSecurityGroup -NetworkSecurityGroup $NSG<\/pre>\n\n<p>\u3061\u306a\u307f\u306b\u30011 \u3064\u306e\u30eb\u30fc\u30eb\u306b\u8907\u6570\u306e\u30a2\u30c9\u30ec\u30b9\u7a7a\u9593\u3092\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001Source \/ Destination Address Prefix \u306b -split \u3067\u30d0\u30e9\u3057\u305f\u914d\u5217\u3092\u7a81\u3063\u8fbc\u3081\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002(\u30a4\u30f3\u30dd\u30fc\u30c8\u7528\u306e CSV \u30b5\u30f3\u30d7\u30eb\u306f<a href=\"https:\/\/blob.syuheiuda.com\/wp-content\/2018\/01\/NSGrules.csv\">\u3053\u3061\u3089<\/a>)<\/p>\n<ul>\n<li>General availability: Augmented rules for NSGs<br><a href=\"https:\/\/azure.microsoft.com\/ja-jp\/updates\/agumented-rules-ga-nsg\/\">https:\/\/azure.microsoft.com\/ja-jp\/updates\/agumented-rules-ga-nsg\/<\/a><\/li>\n<\/ul>\n<p>\u306d\u3001\u7c21\u5358\u3067\u3057\u3087\u3046\uff1f<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NSG \u306b\u5927\u91cf\u306e\u30eb\u30fc\u30eb\u3092\u767b\u9332\u3059\u308b\u5834\u5408\u306a\u3069\u3001\u65e2\u5b58\u306e NSG \u306e\u8a2d\u5b9a\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/www.syuheiuda.com\/?p=4251\">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,31],"tags":[],"views":15902,"_links":{"self":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/4251"}],"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=4251"}],"version-history":[{"count":10,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/4251\/revisions"}],"predecessor-version":[{"id":4762,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=\/wp\/v2\/posts\/4251\/revisions\/4762"}],"wp:attachment":[{"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.syuheiuda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}