{"id":911,"date":"2019-09-23T06:22:15","date_gmt":"2019-09-23T05:22:15","guid":{"rendered":"http:\/\/www.vatland.no\/?p=911"},"modified":"2019-09-23T06:29:03","modified_gmt":"2019-09-23T05:29:03","slug":"use-powershell-to-get-external-ip-address","status":"publish","type":"post","link":"https:\/\/www.vatland.no\/index.php\/use-powershell-to-get-external-ip-address\/","title":{"rendered":"Use powershell to get external IP address"},"content":{"rendered":"\n<p>How can you get your external IP address from powershell? I use a simple script to query an external public web service. The service I&#8217;m using is hosted by ipinfo.io . I have created a small function that is placed in my powershell library. All my modules are loaded by using powershell profiles.<\/p>\n\n\n\n<p>This simple function uses rest. Usage is simple : get-mypublicip . Could easily be uses in script (get-mypublicip).ip .<\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:435px;\"><div class=\"text codecolorer\">function get-mypublicip{<br \/>\n&nbsp; &nbsp; Write-Verbose &quot;Resolving external IP&quot;<br \/>\n&nbsp; &nbsp; try { <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; $ipaddr = Invoke-RestMethod http:\/\/ipinfo.io\/json #| Select-Object -ExpandProperty ip <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; }<br \/>\n&nbsp; &nbsp; catch { <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; throw &quot;Can't get external IP Address. Quitting.&quot; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; }<br \/>\n&nbsp; &nbsp; if ($ipaddr -eq $null) { throw &quot;Can't get external IP Address. Quitting.&quot; }<br \/>\n&nbsp; &nbsp; Write-Verbose &quot;External IP is $ipaddr&quot;<br \/>\n&nbsp; &nbsp; return $ipaddr<br \/>\n}<\/div><\/div>\n\n<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can you get your external IP address from powershell? I use a simple script to query an external public web service. The service I&#8217;m using is hosted by ipinfo.io . I have created a small function that is placed in my powershell library. All my modules are loaded by using powershell profiles. This simple &hellip; <a href=\"https:\/\/www.vatland.no\/index.php\/use-powershell-to-get-external-ip-address\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Use powershell to get external IP address<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","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":[2,48],"tags":[59],"class_list":["post-911","post","type-post","status-publish","format-standard","hentry","category-development","category-powershell","tag-powershell"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[{"id":957,"url":"https:\/\/www.vatland.no\/index.php\/hash-tables-in-powershell\/","url_meta":{"origin":911,"position":0},"title":"Hash tables in powershell","author":"Atle","date":"March 23, 2020","format":false,"excerpt":"We all have the need to store data in some kind of arrays. I use hashtables a lot. Preferred use is as a lookup table, I can use 'contains' instead of looping through each item or reference an object by name instead of index number. Lookup table for licenses is\u2026","rel":"","context":"In &quot;CSP&quot;","block_context":{"text":"CSP","link":"https:\/\/www.vatland.no\/index.php\/category\/csp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":920,"url":"https:\/\/www.vatland.no\/index.php\/get-secretserver-secret\/","url_meta":{"origin":911,"position":1},"title":"Get Secretserver secret","author":"Atle","date":"October 3, 2019","format":false,"excerpt":"Since we are using SecretServer as our credential store it is of great help to be able to get credentials directly from powershell. This is a small function that connects to secretserver webservices and retrieve a secret based on secred ID. The function will connect to the webservice as the\u2026","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/www.vatland.no\/index.php\/category\/development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1146,"url":"https:\/\/www.vatland.no\/index.php\/list-nordpool-electric-prices-using-powershell\/","url_meta":{"origin":911,"position":2},"title":"List NordPool electric prices using powershell.","author":"Atle","date":"January 10, 2022","format":false,"excerpt":"This is a small script using nordpoolgroup api to get todays electric prices for Kr.sand - Norway. This is the same API as their webpage uses. All the urls and parameters can be found using developermode in the browser. This code is only to demonstrate that it can be done.\u2026","rel":"","context":"In \"Api\"","block_context":{"text":"Api","link":"https:\/\/www.vatland.no\/index.php\/tag\/api\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":875,"url":"https:\/\/www.vatland.no\/index.php\/csp-access-to-tenants-using-powershell-part-1\/","url_meta":{"origin":911,"position":3},"title":"CSP access to tenants using powershell. Part 1","author":"Atle","date":"September 18, 2019","format":false,"excerpt":"A short explanation of how to access customer tenant using a CSP tenant SPN credential connectiong to AzureAD and AZ. Have been struggling for a while to manage all our customers tenants using powershell scripts. It can be complicated to organize all the credentials, tenant domain, tenant id's password expiry.\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/azure\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":902,"url":"https:\/\/www.vatland.no\/index.php\/csp-access-to-tenants-using-powershell-part-3\/","url_meta":{"origin":911,"position":4},"title":"CSP access to tenants using powershell. Part 3","author":"Atle","date":"September 23, 2019","format":false,"excerpt":"In this part 3 of CSP and powershell I will show how you can connect to azureAD of a customer tenant using your CSP app credentials and refreshtoken. This is almost the same procedure as we use to connect to az. We will start with the same variables as in\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/azure\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":934,"url":"https:\/\/www.vatland.no\/index.php\/simple-powershell-mru-list\/","url_meta":{"origin":911,"position":5},"title":"Simple Powershell MRU list","author":"Atle","date":"December 23, 2019","format":false,"excerpt":"When using using my secret server powershell functions I got tired of constantly searching for secret ID's. I had to do a new search just because I could not remember the ID's. So I added some kind of MRU to my get-secretID function. This code block creates to classes mruitem\u2026","rel":"","context":"In &quot;Powershell&quot;","block_context":{"text":"Powershell","link":"https:\/\/www.vatland.no\/index.php\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/comments?post=911"}],"version-history":[{"count":2,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/911\/revisions"}],"predecessor-version":[{"id":913,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/911\/revisions\/913"}],"wp:attachment":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/media?parent=911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/categories?post=911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/tags?post=911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}