{"id":489,"date":"2018-11-26T08:00:02","date_gmt":"2018-11-26T14:00:02","guid":{"rendered":"https:\/\/practicalpowershell.com\/?p=489"},"modified":"2020-03-14T10:10:37","modified_gmt":"2020-03-14T16:10:37","slug":"managing-your-connections","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/managing-your-connections\/","title":{"rendered":"Managing Your Connections"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?resize=150%2C150&#038;ssl=1\" alt=\"\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-490\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?resize=100%2C100&amp;ssl=1 100w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>When working with on-premises servers we may not thing about the remote PowerShell connections that are made, whether they are broken or if they could cause issues with the connected server at all. When it comes to cloud services, these remote connections become even more important. Having too many connections open is not good for your tenant and Microsoft has put a limit on the number of connections you can make as documented here:<BR><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/office365\/enterprise\/powershell\/connect-to-exchange-online-tenants-with-remote-windows-powershell-for-delegated\">https:\/\/docs.microsoft.com\/en-us\/office365\/enterprise\/powershell\/connect-to-exchange-online-tenants-with-remote-windows-powershell-for-delegated<\/a><BR><br \/>\n&#8220;There&#8217;s a limit of three simultaneous sessions that can run under one account.&#8221;<BR><br \/>\nSo when working with PowerShell to manage your Office 365 tenant, proper cleanup of connections should be forefront of your scripts. Again, a typical script for on-premises servers pays no attention to these connections. However, with Office 365, a conscientious effort needs to be taken. This means adding code to a script to close any open connections when the connections are no longer needed. The code is relatively simple:<BR><br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nGet-PSSession | Remove-PSSession<br \/>\n[\/sourcecode]<br \/>\nThere should be no feedback if the cmdlet executes successfully. Another reason to cleanup PowerShell sessions is if they are broken. This could happen with a timeout if a PowerShell windows is left to idle too long, or if there is an issue on the Office 365 side of the connection. Often if you were to execute a PowerShell cmdlet in a window where the connection is broken, an authentication prompt could occur.<BR><br \/>\nSometimes the cmdlets do not work at all. If you run &#8216;Get-PSSession&#8217; you may see broken PowerShell connections. closing these sessions and opening new ones may not resolve the issue. Closing the PowerShell window and opening a new one should resolve the issue.<BR><br \/>\n<em>Conclusion<\/em><BR><br \/>\nImportant cmdlets for PowerShell session management:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nGet-PSSession<br \/>\nRemove-PSSession<br \/>\n[\/sourcecode]<br \/>\nJust remember to cleanup your connections, or you may experience issues if you hit the limit or are left with stale broken connections.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working with on-premises servers we may not thing about the remote PowerShell connections that are made, whether they are broken or if they could cause issues with the connected server at all. When it comes to cloud services, these remote connections become even more important. Having too many connections open is not good for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-489","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Managing Your Connections - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/managing-your-connections\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Managing Your Connections - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"When working with on-premises servers we may not thing about the remote PowerShell connections that are made, whether they are broken or if they could cause issues with the connected server at all. When it comes to cloud services, these remote connections become even more important. Having too many connections open is not good for [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/managing-your-connections\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-26T14:00:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-14T16:10:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections-150x150.png\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"Managing Your Connections\",\"datePublished\":\"2018-11-26T14:00:02+00:00\",\"dateModified\":\"2020-03-14T16:10:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/\"},\"wordCount\":324,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Connections-150x150.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/\",\"name\":\"Managing Your Connections - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Connections-150x150.png\",\"datePublished\":\"2018-11-26T14:00:02+00:00\",\"dateModified\":\"2020-03-14T16:10:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Connections.png?fit=150%2C155&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Connections.png?fit=150%2C155&ssl=1\",\"width\":150,\"height\":155},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/managing-your-connections\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Managing Your Connections\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Managing Your Connections - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/managing-your-connections\/","og_locale":"en_US","og_type":"article","og_title":"Managing Your Connections - Practical PowerShell","og_description":"When working with on-premises servers we may not thing about the remote PowerShell connections that are made, whether they are broken or if they could cause issues with the connected server at all. When it comes to cloud services, these remote connections become even more important. Having too many connections open is not good for [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/managing-your-connections\/","og_site_name":"Practical PowerShell","article_published_time":"2018-11-26T14:00:02+00:00","article_modified_time":"2020-03-14T16:10:37+00:00","og_image":[{"url":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections-150x150.png","type":"","width":"","height":""}],"author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"Managing Your Connections","datePublished":"2018-11-26T14:00:02+00:00","dateModified":"2020-03-14T16:10:37+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/"},"wordCount":324,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"image":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections-150x150.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/managing-your-connections\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/","url":"https:\/\/practicalpowershell.com\/managing-your-connections\/","name":"Managing Your Connections - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#primaryimage"},"image":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections-150x150.png","datePublished":"2018-11-26T14:00:02+00:00","dateModified":"2020-03-14T16:10:37+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/managing-your-connections\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#primaryimage","url":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?fit=150%2C155&ssl=1","contentUrl":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Connections.png?fit=150%2C155&ssl=1","width":150,"height":155},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/managing-your-connections\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"Managing Your Connections"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=489"}],"version-history":[{"count":1,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/489\/revisions"}],"predecessor-version":[{"id":491,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/489\/revisions\/491"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}