Powershell working, but not stopping

Hello,

I’ve managed to get this script to pull the number of files in a folder to a database (influx), I can see the data in there, but the PS script doesn’t end/stop unless I manually cancel it. What do I need to add/change?

Import-Module Influx
 
$user = 'filecountuser1'
$file = 'C:\test\pwdsmtp.txt'
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, (Get-Content $file | ConvertTo-SecureString)
 
While ($true){  
    $Metrics = @{
        FolderCount = [int](Get-ChildItem \\server1\temp\Test | Measure-Object).Count
        }
    Write-Influx -Measure filecount -Tags @{host="server1"} -Metrics $Metrics -Database "filecountDB" -Server http://10.10.12.65:8086 -Credential $credentials
    Start-Sleep -Seconds 30
}

Thanks

I think it’s this, I assumed it sleep would stop it :smiley:

You are in an endless loop setting your While trigger to $true.

Additionally, you seem to be checking a single host so why is the loop even necessary?

3 Likes