{"id":78325,"date":"2016-05-27T00:01:44","date_gmt":"2016-05-27T07:01:44","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=78325"},"modified":"2019-02-18T09:10:44","modified_gmt":"2019-02-18T16:10:44","slug":"work-with-the-azure-resource-manager-cmdlets-part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/work-with-the-azure-resource-manager-cmdlets-part-5\/","title":{"rendered":"Work with the Azure Resource Manager cmdlets \u2013 Part 5"},"content":{"rendered":"<p><strong>Summary<\/strong>: Here&#8217;s how to use PowerShell to create a virtual network and a network security group.<\/p>\n<p>This blog post is part of a series about how to work with the Azure Resource Manager cmdlets. To get the most out of this series, read the posts in order.<\/p>\n<ul>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/23\/work-with-the-azurerm-cmdlets-part-1\/\">Work with the Azure Resource Manager cmdlets \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/24\/work-with-the-azurerm-cmdlets-part-2\/\">Work with the Azure Resource Manager cmdlets \u2013 Part 2<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/25\/work-with-the-azurerm-cmdlets-part-3\/\">Work with the Azure Resource Manager cmdlets \u2013 Part 3<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/26\/work-with-the-azure-resource-manager-cmdlets-part-4\/\">Work with the Azure Resource Manager cmdlets \u2013 Part 4<\/a><\/li>\n<li>Work with the Azure Resource Manager cmdlets \u2013 Part 5<\/li>\n<\/ul>\n<p>After you finish this series, move on to the next two series to learn more about the Azure Resource Manager cmdlets.<\/p>\n<ul>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/30\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-1\/\">Retrieve Azure Resource Manager virtual machine properties by using PowerShell<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/06\/06\/create-azure-resource-manager-virtual-machines-by-using-powershell-part-1\/\">Create Azure Resource Manager virtual machines by using PowerShell<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>\u00a0I\u2019ve heard that networking is far more powerful in Azure Resource Manager. Could you take a few minutes to show me how to use PowerShell to set up a basic network for virtual machines (VMs) in Azure?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>\u00a0Honorary Scripting Guy, Sean Kearney, is here to polish off our basic introduction to the Azure Resource Manager cmdlets. Our goal this week has really been to get you familiar with some of the rudimentary setup that\u2019s needed on the backend for Azure VMs. In addition, of course, because we\u2019re the Scripting Guys, we needed to show you how to do it all in PowerShell.<\/p>\n<p>Within the Azure portal, you\u2019ll create two key pieces to give yourself a useful network infrastructure for your VMs.<\/p>\n<p>The first is a virtual network. This is a defined IP range for a network.<\/p>\n<p>The process to create a virtual network is quite similar to other processes that create resources\u00a0in Azure Resource Manager.<\/p>\n<p>Choose <strong>New<\/strong> from the Azure portal and enter <strong>network<\/strong> in the search box. This will prompt you with some options. You\u2019ll select <strong>Virtual Network<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78335\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-052716.png\" alt=\"Screenshot of the search box that includes the word, network.\" width=\"565\" height=\"181\" \/><\/a><\/p>\n<p>You\u2019ll need to select <strong>Virtual Network<\/strong> in the window.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78345\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-052716.png\" alt=\"Screenshot of search results, which includes Virtual network.\" width=\"672\" height=\"141\" \/><\/a><\/p>\n<p>This will bring up a lovely little window for all our viewing audience that provides a decent description of a virtual network. But at this point, I think you should click the blue <strong>Create<\/strong> button to get things going.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78355\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-052716.png\" alt=\"Screenshot of a window that includes a description of a virtual network.\" width=\"567\" height=\"382\" \/><\/a><\/p>\n<p>At this point, you\u2019ll see the wizard that\u00a0configures your virtual network.<\/p>\n<p>We need to provide the following details:<\/p>\n<ul>\n<li>Name<\/li>\n<li>Address range (10.0.0.0\/8, 172.16.0.0\/16, 192.168.0.0\/16)<\/li>\n<li>Name for subnet<\/li>\n<li>IP range for the subnet (a smaller subnet of your defined address range)<\/li>\n<li>Name of your subscription<\/li>\n<li>The resource group to assign this network to<\/li>\n<li>Location<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78365\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-052716.png\" alt=\"Screenshot of the Create virtual network page that has completed information for the virtual network.\" width=\"332\" height=\"565\" \/><\/a><\/p>\n<p>After you click the ever popular blue <strong>Create<\/strong> button, the creation of this network will begin.<\/p>\n<p>Now, I\u2019ll bet you\u2019d like to see the <span style=\"text-decoration: underline\">easy<\/span> way to do this, wouldn\u2019t you?<\/p>\n<p>Provide the same information to two cmdlets, <strong>New-AzureRMVirtualNetworkSubnetConfig<\/strong> and <strong>New-AzureRMVirtualNetwork<\/strong>.<\/p>\n<p>First, we define the properties of the subnet:<\/p>\n<p style=\"padding-left: 30px\"><code>$SNName='HSG-Default'\n$SNAddressPrefix='10.0.0.0\/24'$Subnet=New-AzureRmVirtualNetworkSubnetConfig -Name $SNName -AddressPrefix $SNAddressPrefix<\/code><\/p>\n<p>Then, we add that subnet to our virtual network and create it.<\/p>\n<p style=\"padding-left: 30px\"><code>$RGName=\u2019HSG-AzureRG\u2019\n$Location=\u2019East US\u2019\n$VNAddressPrefix='10.0.0.0\/16'\n$VNName='HSG-VirtualNetwork'\n$AzureNet=New-AzureRmVirtualNetwork -Name $VNName -ResourceGroupName $RGName -Location $location -AddressPrefix $VNAddressPrefix -Subnet $Subnet<\/code><\/p>\n<p>The other component that we need to populate is the network security group. This is the component in Azure Resource Manager that wraps around the various virtual networks to provide rudimentary firewall rules.<\/p>\n<p>Security groups provide some basic isolation from our development, quality assurance, preproduction, and production environments that are all on the same subscription.<\/p>\n<p>Creating a security group in Azure is also quite simple. Choose <strong>New<\/strong> from the Azure portal, and enter <strong>network security<\/strong> in the search box. This will prompt you with some options. You\u2019ll select <strong>Network security group<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78375\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-052716.png\" alt=\"Screenshot of the search box that includes the word, network security.\" width=\"554\" height=\"228\" \/><\/a><\/p>\n<p>You\u2019ll need to select <strong>Network security group<\/strong> from the window.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78385\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-052716.png\" alt=\"Screenshot of search results that includes an entry for Network security group.\" width=\"601\" height=\"139\" \/><\/a><\/p>\n<p>This will open yet another window with some light afternoon reading about network security groups. Let\u2019s click the blue <strong>Create<\/strong> button and get to the nitty gritty.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78395\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-052716.png\" alt=\"Screenshot of a window that includes a description of a Network security group.\" width=\"507\" height=\"672\" \/><\/a><\/p>\n<p>We now can create the network security group, which needs just the following information to set up:<\/p>\n<ul>\n<li>A name for the group<\/li>\n<li>The subscription that it\u2019s assigned to<\/li>\n<li>A resource group that it should be a member of<\/li>\n<li>Location<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8-HSG-052716.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78405\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8-HSG-052716.png\" alt=\"Screenshot of the Create network security group page that has completed information for the security group.\" width=\"318\" height=\"375\" \/><\/a><\/p>\n<p>Click that blue <strong>Create<\/strong> button, and you\u2019ll be done.<\/p>\n<p>Now that was an <span style=\"text-decoration: underline\">awful<\/span> lot of screenshots for what I suspect should be a teeny bit of PowerShell, which it is!<\/p>\n<p style=\"padding-left: 30px\"><code>$Name=\u2019HSG-NetworkSecurityGroup\u2019\n$RGName=\u2019HSG-AzureRG\u2019\n$Location=\u2019East US\u2019\nNew-AzureRMNetworkSecurityGroup \u2013Name $Name \u2013resourcegroup $RGName \u2013Location $Location<\/code><\/p>\n<p>Although working through the GUI may seem tedious, the point of this week is twofold. One is to get a basic Infrastructure configured for VMs, which we\u2019ll use over the next two weeks. The second is to give you a side-by-side comparison of the graphical process and the matching PowerShell process.<\/p>\n<p>Stick around for next week when we spin up a VM within Azure Resource Manager and show you how to access all of its resources to reuse in future VM.<\/p>\n<p>That is all there is to our basic introduction about\u00a0how to use the Azure Resource Manager cmdlets to configure the backend for VMs. Next week will continue as we talk about how to us these same cmdlets to pull the properties to create new VMs.<\/p>\n<p>I invite you to follow the Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to them at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow.<\/p>\n<p>Until then always remember that with Great PowerShell comes Great Responsibility.<\/p>\n<p><strong>Sean Kearney\n<\/strong>Honorary Scripting Guy\nCloud and Datacenter Management MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Here&#8217;s how to use PowerShell to create a virtual network and a network security group. This blog post is part of a series about how to work with the Azure Resource Manager cmdlets. To get the most out of this series, read the posts in order. Work with the Azure Resource Manager cmdlets \u2013 [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,641],"tags":[56,154,45],"class_list":["post-78325","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-windows-powershell","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Here&#8217;s how to use PowerShell to create a virtual network and a network security group. This blog post is part of a series about how to work with the Azure Resource Manager cmdlets. To get the most out of this series, read the posts in order. Work with the Azure Resource Manager cmdlets \u2013 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/78325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=78325"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/78325\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=78325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=78325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=78325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}