{"id":79255,"date":"2016-07-01T00:01:45","date_gmt":"2016-07-01T07:01:45","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=79255"},"modified":"2019-02-18T09:10:32","modified_gmt":"2019-02-18T16:10:32","slug":"how-to-alter-the-public-ip-address-of-an-azure-virtual-machine","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-to-alter-the-public-ip-address-of-an-azure-virtual-machine\/","title":{"rendered":"How to alter the public IP address of an Azure virtual machine"},"content":{"rendered":"<p><strong>Summary<\/strong>: Change the public IP address in Azure Resource Manager by using Windows PowerShell.<\/p>\n<p>Honorary Scripting Guy, Will Anderson, shares a personal challenge that he encountered when working with Azure and public IP addresses. He also shares the solution with the rest of us!<\/p>\n<p>Take it away, Will!<\/p>\n<p>Recently, I incorrectly configured an Azure Resource Manager virtual machine (VM) in my lab environment and needed to make some changes to the public IP settings. A brief look around the Internet came up empty, so I thought I&#8217;d share the challenge and the solution to this puzzle with you.<\/p>\n<h2>The challenge<\/h2>\n<p>If we take a look at <strong>Set-AzureRmPublicIpAddress<\/strong>, it uses only one parameter: <strong>-PublicIPAddress<\/strong>. To actually change the properties in the object, however, we need to call them. How do we do that? It depends on the property in question, so I&#8217;ll give you an example of two different properties that we&#8217;re going to change on our target VM. In this example, we&#8217;re going to change our public IP allocation from Dynamic to Static, and we&#8217;re going to give our PublicIP a friendly name and a fully qualified domain name (FQDN).<\/p>\n<h2>Data formatting or using an existing example<\/h2>\n<p>We can look up an existing PublicIP configuration by doing the following:<\/p>\n<p style=\"padding-left: 60px\"><code>$ExResGrp = Get-AzureRmResourceGroup -Name 'lwindsc'<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$PubIP = (Get-AzureRmPublicIpAddress -ResourceGroupName $ExResGrp.ResourceGroupName).where({$PSItem.Name -eq 'lwindsctgtwestuspubip'})<\/code><\/p>\n<p>And as we can see, we have a configuration to look at:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-070116.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-79265\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-070116.jpg\" alt=\"Screenshot of results that show an existing PublicIP configuration.\" width=\"633\" height=\"275\" \/><\/a><\/p>\n<p>The <strong>PublicIpAllocationMethod<\/strong>, where we define our configuration as Static or Dynamic, is a simple string, which is easy enough to pass along. But, if you notice, the <strong>DNSSettings<\/strong> are displayed in a hashtable. So, let&#8217;s construct our changes. First, we cast our target PublicIP configuration object to a variable:<\/p>\n<p style=\"padding-left: 60px\"><code>$TgtResGrp = Get-AzureRmResourceGroup -Name 'lwinpubip'<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$PubIP = Get-AzureRmPublicIpAddress -ResourceGroupName $TgtResGrp.ResourceGroupName<\/code><\/p>\n<p>If we call the object, we&#8217;ll see that the <strong>PublicIpAllocationMethod<\/strong> is set to <strong>Dynamic<\/strong>, and the <strong>DnsSettings<\/strong> property is <strong>null<\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-070116.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-79295\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-070116.jpg\" alt=\"Screenshot that shows that the PublicIpAllocationMethod is Dynamic and the DnsSettings property is null.\" width=\"732\" height=\"220\" \/><\/a><\/p>\n<h2>Make the change<\/h2>\n<p>Now we call the properties that we want to modify and the values that we want to input.<\/p>\n<p style=\"padding-left: 60px\"><code>$PubIp.PublicIpAllocationMethod = 'Static'\n$PubIP.DnsSettings = @{<\/code><\/p>\n<p style=\"padding-left: 120px\"><code>'DomainNameLabel' = ($TgtResGrp.ResourceGroupName + $TgtResGrp.Location + 'pubip')\n'Fqdn' = ($TgtResGrp.ResourceGroupName + '.westus.cloudapp.azure.com')<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>}<\/code><\/p>\n<p>If we look at our stored object, we can see the changes that we&#8217;ve made:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-070116.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-79285\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-070116.jpg\" alt=\"Screenshot that shows that the PublicIpAllocationMethod is changed to Static and the DnsSettings property is no longer null.\" width=\"578\" height=\"280\" \/><\/a><\/p>\n<p>Now we commit the changes to Azure by passing our object back with <strong>Set-AzureRmPublicIpAddress<\/strong>.<\/p>\n<p style=\"padding-left: 60px\"><code>$PubIP | Set-AzureRmPublicIpAddress<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-070116.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-79305\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-070116.jpg\" alt=\"Screenshot that shows results after pass the object back with Set-AzureRmPublicIpAddress.\" width=\"591\" height=\"300\" \/><\/a><\/p>\n<p>And now our system is accessible remotely by a friendly name!<\/p>\n<p>Thanks, Will, for sharing that with the community! I\u2019m certain you\u2019ve made somebody\u2019s day!<\/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>Will Anderson\n<\/strong>Honorary Scripting Guy\nCloud and Datacenter Management MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Change the public IP address in Azure Resource Manager by using Windows PowerShell. Honorary Scripting Guy, Will Anderson, shares a personal challenge that he encountered when working with Azure and public IP addresses. He also shares the solution with the rest of us! Take it away, Will! Recently, I incorrectly configured an Azure Resource [&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,685,641],"tags":[56,579,45],"class_list":["post-79255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-scripting-techniques","category-windows-powershell","tag-guest-blogger","tag-will-anderson","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Change the public IP address in Azure Resource Manager by using Windows PowerShell. Honorary Scripting Guy, Will Anderson, shares a personal challenge that he encountered when working with Azure and public IP addresses. He also shares the solution with the rest of us! Take it away, Will! Recently, I incorrectly configured an Azure Resource [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/79255","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=79255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/79255\/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=79255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=79255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=79255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}