{"id":1825,"date":"2017-09-25T21:59:54","date_gmt":"2017-09-25T13:59:54","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/?p=1825"},"modified":"2017-09-25T22:20:47","modified_gmt":"2017-09-25T14:20:47","slug":"addressing-the-powershell-garbage-collection-bug","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825","title":{"rendered":"Addressing the PowerShell Garbage Collection bug"},"content":{"rendered":"<p>There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object.<\/p>\n<p>Simply using <strong>[System.GC]::Collect()<\/strong> within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you&#8217;re script is processing large objects. You can potentially exhaust memory resources and your script will fail with out of memory errors. This has been driving me nuts for years, as many of my <a href=\"http:\/\/www.jhouseconsulting.com\/2014\/05\/15\/active-directory-health-check-audit-and-remediation-scripts-1301\" target=\"_blank\">Active Directory Health Check, Audit and Remediation Scripts<\/a> process large objects in large environments.<\/p>\n<p>There is a good overview of the bug here:&nbsp;<a href=\"https:\/\/stackoverflow.com\/questions\/31620763\/no-garbage-collection-while-powershell-pipeline-is-executing\" target=\"_blank\">No garbage collection while PowerShell pipeline is executing<\/a>. Whilst this post claims that it seems to have been resolved in PowerShell 5, this doesn&#8217;t appear to be the&nbsp;case from my testing.<!--more--><\/p>\n<p>Here&#8217;s what was happening to powershell.exe after processing a couple of hundred users using my <a href=\"http:\/\/www.jhouseconsulting.com\/2013\/12\/20\/script-to-create-a-kerberos-token-size-report-1041\" target=\"_blank\">script to create a Kerberos Token Size Report<\/a>&#8230;<\/p>\n<p><a href=\"http:\/\/www.jhouseconsulting.com\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\/powershell-garbage-collection-bug-no-action\" rel=\"attachment wp-att-1831\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-1831\" title=\"PowerShell Garbage Collection bug\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-no-action-e1506348358607.png\" alt=\"PowerShell Garbage Collection bug\" width=\"601\" height=\"236\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-no-action-e1506348358607.png 639w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-no-action-e1506348358607-300x118.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>It continually grows&#8230;and grows&#8230;and grows.<\/p>\n<p>Just by chance, and trying to add some smarts to my scripts for memory usage reporting, I found a way around this. Simply use&#8230;<\/p>\n<p><strong>[System.GC]::GetTotalMemory(&#8216;forcefullcollection&#8217;) | out-null<\/strong><\/p>\n<p>or<\/p>\n<p><strong>[System.GC]::GetTotalMemory($true) | out-null<\/strong><\/p>\n<p>Where $true or &#8216;forceFullCollection&#8217; is used to indicate that this method can wait for garbage collection to occur before returning.<\/p>\n<p>Even though [System.GC]::Collect() does not force a garbage collection whilst executing in a pipeline or loop of an object, [System.GC]::GetTotalMemory() with either $true or &#8216;forceFullCollection&#8217; does indeed successfully force a garbage collection. Wow! Go figure! My testing so far has found this to be a reliable method to use across different versions of PowerShell.<\/p>\n<p>So now here is what happens to powershell.exe after processing a couple of hundred users using the same script&#8230;<\/p>\n<p><a href=\"http:\/\/www.jhouseconsulting.com\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\/powershell-garbage-collection-bug-before-fix\" rel=\"attachment wp-att-1830\"><img decoding=\"async\" class=\"aligncenter wp-image-1830\" title=\"PowerShell Garbage Collection bug gone after fix\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-before-fix-e1506348302240.png\" alt=\"PowerShell Garbage Collection bug gone after fix\" width=\"601\" height=\"238\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-before-fix-e1506348302240.png 639w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-before-fix-e1506348302240-300x119.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>A massive difference in memory usage, which doesn&#8217;t really grow too much further even after processing tens of thousands of users in the object.<\/p>\n<p>I&#8217;ve actually taken this one step further and have started to add a function to my scripts to dynamically report on memory allocated to the managed components. It only reports the bytes allocated by the PowerShell scripting engine and does not account for the memory used by the PowerShell engine itself as can be seen in Task Manager. But I really like this function:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.codeday.top\/2017\/01\/19\/14333.html\" target=\"_blank\">The PowerShell implementation dynamically gets the memory consumed by the current script runtime<\/a><\/li>\n<li><a href=\"http:\/\/community.idera.com\/powershell\/powertips\/b\/tips\/posts\/get-memory-consumption\" target=\"_blank\">Get Memory Consumption<\/a><\/li>\n<\/ul>\n<p>This is one of the many vagaries of PowerShell that&#8217;s been annoying me for a very long time.<\/p>\n<p>I hope this helps anyone else struggling with the same challenges.<\/p>\n<p>Happy scripting \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you&#8217;re script is &#8230; <a title=\"Addressing the PowerShell Garbage Collection bug\" class=\"read-more\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\" aria-label=\"Read more about Addressing the PowerShell Garbage Collection bug\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[5],"tags":[157,503,505,501,504,511,510,509,340,512,502,513,508,507,506],"class_list":["post-1825","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-bug","tag-collect","tag-forcefullcollection","tag-garbage-collection","tag-gettotalmemory","tag-leak","tag-memory","tag-memory-leak","tag-powershell","tag-powershell-exe","tag-system-gc","tag-task-manager","tag-system-gccollect","tag-system-gcgettotalmemorytrue","tag-system-gcgettotalmemoryforcefullcollection"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you&#039;re script is\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Jeremy Saunders\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846 - Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846\" \/>\n\t\t<meta property=\"og:description\" content=\"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you&#039;re script is\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2017-09-25T13:59:54+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2017-09-25T14:20:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846\" \/>\n\t\t<meta name=\"twitter:description\" content=\"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you&#039;re script is\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#blogposting\",\"name\":\"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846\",\"headline\":\"Addressing the PowerShell Garbage Collection bug\",\"author\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/author\\\/jeremy#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/wp-content\\\/uploads\\\/2017\\\/09\\\/PowerShell-Garbage-Collection-bug-no-action-e1506348358607.png\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825\\\/#articleImage\",\"width\":639,\"height\":251,\"caption\":\"PowerShell Garbage Collection bug\"},\"datePublished\":\"2017-09-25T21:59:54+08:00\",\"dateModified\":\"2017-09-25T22:20:47+08:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#webpage\"},\"articleSection\":\"Scripting, bug, Collect, forcefullcollection, Garbage Collection, GetTotalMemory, leak, memory, memory leak, PowerShell, powershell.exe, System.GC, Task Manager, [System.GC]::Collect(), [System.GC]::GetTotalMemory($true), [System.GC]::GetTotalMemory('forcefullcollection')\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/category\\\/scripting#listItem\",\"name\":\"Scripting\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/category\\\/scripting#listItem\",\"position\":2,\"name\":\"Scripting\",\"item\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/category\\\/scripting\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#listItem\",\"name\":\"Addressing the PowerShell Garbage Collection bug\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#listItem\",\"position\":3,\"name\":\"Addressing the PowerShell Garbage Collection bug\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/category\\\/scripting#listItem\",\"name\":\"Scripting\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/#organization\",\"name\":\"J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846\",\"description\":\"Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/Blog-Banner-White-JeremySaunders-1.png\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825\\\/#organizationLogo\",\"width\":1020,\"height\":200},\"image\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/author\\\/jeremy#author\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/author\\\/jeremy\",\"name\":\"Jeremy Saunders\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f2d27bd3d985e6ef2024dded7c713b14440d467a6a0100aede3cfefcb4ab20f1?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Jeremy Saunders\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#webpage\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825\",\"name\":\"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846\",\"description\":\"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you're script is\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/2017\\\/09\\\/25\\\/addressing-the-powershell-garbage-collection-bug-1825#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/author\\\/jeremy#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/author\\\/jeremy#author\"},\"datePublished\":\"2017-09-25T21:59:54+08:00\",\"dateModified\":\"2017-09-25T22:20:47+08:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/#website\",\"url\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/\",\"name\":\"J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846\",\"description\":\"Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.jhouseconsulting.com\\\/jhouseconsulting\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846","description":"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you're script is","canonical_url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#blogposting","name":"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846","headline":"Addressing the PowerShell Garbage Collection bug","author":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/author\/jeremy#author"},"publisher":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2017\/09\/PowerShell-Garbage-Collection-bug-no-action-e1506348358607.png","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\/#articleImage","width":639,"height":251,"caption":"PowerShell Garbage Collection bug"},"datePublished":"2017-09-25T21:59:54+08:00","dateModified":"2017-09-25T22:20:47+08:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#webpage"},"isPartOf":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#webpage"},"articleSection":"Scripting, bug, Collect, forcefullcollection, Garbage Collection, GetTotalMemory, leak, memory, memory leak, PowerShell, powershell.exe, System.GC, Task Manager, [System.GC]::Collect(), [System.GC]::GetTotalMemory($true), [System.GC]::GetTotalMemory('forcefullcollection')"},{"@type":"BreadcrumbList","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting#listItem","position":1,"name":"Home","item":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting","nextItem":{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting#listItem","name":"Scripting"}},{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting#listItem","position":2,"name":"Scripting","item":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting","nextItem":{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#listItem","name":"Addressing the PowerShell Garbage Collection bug"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#listItem","position":3,"name":"Addressing the PowerShell Garbage Collection bug","previousItem":{"@type":"ListItem","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting#listItem","name":"Scripting"}}]},{"@type":"Organization","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/#organization","name":"J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846","description":"Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/","logo":{"@type":"ImageObject","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\/#organizationLogo","width":1020,"height":200},"image":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/author\/jeremy#author","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/author\/jeremy","name":"Jeremy Saunders","image":{"@type":"ImageObject","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/f2d27bd3d985e6ef2024dded7c713b14440d467a6a0100aede3cfefcb4ab20f1?s=96&d=mm&r=g","width":96,"height":96,"caption":"Jeremy Saunders"}},{"@type":"WebPage","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#webpage","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825","name":"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846","description":"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you're script is","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/#website"},"breadcrumb":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825#breadcrumblist"},"author":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/author\/jeremy#author"},"creator":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/author\/jeremy#author"},"datePublished":"2017-09-25T21:59:54+08:00","dateModified":"2017-09-25T22:20:47+08:00"},{"@type":"WebSite","@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/#website","url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/","name":"J House Consulting - DevOps, Microsoft, Citrix & Desktop Virtualisation (VDI) Specialist - +61 413 441 846","description":"Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/#organization"}}]},"og:locale":"en_US","og:site_name":"J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846 - Delivering customer success through technology: IT Infrastructure | Citrix | End User Computing | Platform Engineering | DevOps | Full Stack Developer | Technical Architect | Improvisor | Aspiring Comedian | Midlife Adventurer","og:type":"article","og:title":"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846","og:description":"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you're script is","og:url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825","og:image":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png","og:image:secure_url":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png","article:published_time":"2017-09-25T13:59:54+00:00","article:modified_time":"2017-09-25T14:20:47+00:00","twitter:card":"summary_large_image","twitter:title":"Addressing the PowerShell Garbage Collection bug - J House Consulting - DevOps, Microsoft, Citrix &amp; Desktop Virtualisation (VDI) Specialist - +61 413 441 846","twitter:description":"There is a known bug where PowerShell does not correctly manage a garbage collection whilst executing a pipeline or loop of an object. Simply using [System.GC]::Collect() within the pipeline or loop does not work as expected. Memory continually grows until the pipeline or loop has completed. This becomes a serious problem if you're script is","twitter:image":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2025\/06\/Blog-Banner-White-JeremySaunders-1.png"},"aioseo_meta_data":{"post_id":"1825","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2025-07-04 13:44:26","updated":"2025-07-04 13:44:26","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting\" title=\"Scripting\">Scripting<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAddressing the PowerShell Garbage Collection bug\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting"},{"label":"Scripting","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/category\/scripting"},{"label":"Addressing the PowerShell Garbage Collection bug","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2017\/09\/25\/addressing-the-powershell-garbage-collection-bug-1825"}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=1825"}],"version-history":[{"count":5,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"predecessor-version":[{"id":1844,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/1825\/revisions\/1844"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}