Solved

Powershell continous loop memory consumption

Posted on 2016-10-10
6
38 Views
Last Modified: 2016-10-11
Hi I'm running a continuous loop, and running into a memory issue

$date=(get-date).day
while($date -eq ((get-date).day))
{
   
    Start-Sleep -Seconds 10
   

}

memory consumption of powershell.exe increases over time is there a way to keep it in check for this simple loop?
0
Comment
Question by:mcazabonnet
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41837427
You can try adding in garbage collection to your loop and see if it will free up the memory.  It's a .NET class you could call every 100 iterations (or so).

$i = 0
$date=(get-date).day
while($date -eq ((get-date).day))
{
    Start-Sleep -Seconds 10
    
    Write-Host OK...
    if ($i -eq 100)
    {
        [System.GC]::Collect()
        $i = 0
    }
    $i++
}

Open in new window

1
 
LVL 69

Expert Comment

by:Qlemo
ID: 41837577
Do you really run only this simple loop? Certainly not - and then the other stuff might be the culprit.
If all you do the loop for is to wait, then you should just run a single sleep with the correct number of seconds.
0
 
LVL 4

Author Comment

by:mcazabonnet
ID: 41837621
Awesome thx!...
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 4

Author Closing Comment

by:mcazabonnet
ID: 41837622
Thx...
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 41837937
Does that really help?
0
 
LVL 4

Author Comment

by:mcazabonnet
ID: 41838265
i ran this simple loop and the [GC.System]::Collect does prevent the powershell.exe thread from increasing in memory. (You can test yourself)
I have it running every 15 minutes on my current service
I do have a complex process running based on user demand, and the working memory on the iis server is not increasing in size
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell Script Request / Suggestion 6 45
powershell add-content , set-content 2 22
Never expired checked 2 18
Recycle MSExchnge powershell app Pool 2 16
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question