# Powershell working, but not stopping

**URL:** <https://forums.powershell.org/t/powershell-working-but-not-stopping/22702>\
**Category:** PowerShell Help\
**Created:** [August 2, 2023, 3:50pm UTC](https://forums.powershell.org/t/powershell-working-but-not-stopping/22702 "2023-08-02T15:50:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Turrican](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Turrican](https://forums.powershell.org/u/Turrican)\
**Post date:** [August 2, 2023, 3:50pm UTC](https://forums.powershell.org/t/powershell-working-but-not-stopping/22702/1 "2023-08-02T15:50:10Z")

</div>

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![Turrican](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Turrican](https://forums.powershell.org/u/Turrican)\
**Post date:** [August 2, 2023, 4:18pm UTC](https://forums.powershell.org/t/powershell-working-but-not-stopping/22702/2 "2023-08-02T16:18:24Z")

</div>

> [@Turrican](#):
>
> `Start-Sleep -Seconds 30`

I think it’s this, I assumed it sleep would stop it 😃

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [August 2, 2023, 4:32pm UTC](https://forums.powershell.org/t/powershell-working-but-not-stopping/22702/3 "2023-08-02T16:32:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/powershell-working-but-not-stopping/22702/4 "2024-05-16T20:14:45Z")

</div>


