File check PRIOR to conducting an IIS Reset help

I am building a script, but having issues, i need to create a “Check” that the files have been created in a folder BEFORE resetting IIS, i have tried using a wait cmd for 10 minutes, but the server is temperamental, so looking at a way to add a line that confirms all 8 files have been written to the directory and then performing an IIS Reset

This is what im currently using

Restart-Service "************** Register Service"
Get-ChildItem -Path 'E:\***\ProductEngineCache\' *.bin | foreach { Remove-Item -Path $_.FullName }
Get-ChildItem -Path 'E:\***\ProductEngineCache\' *.txt | foreach { Remove-Item -Path $_.FullName }
& "E:\***\***FmaBslCore\ProductsEngineCacheConsole\***.Fma.Bsl.ProductsEngineCacheConsole.exe" /run /exit /SilentMode
Start "E:\***\ProductEngineCache"
Start-Sleep -s 600
& {iisreset}

Also is it possible to add a line to confirm that operation is now complete, ie Files have been written to folder and IIS reset has successfully completed

Any suggestions or pointers appreciated

Hi, welcome to the forum :wave:

To recommend the best solution it would be good to know a bit more about the files. Are they the only eight files in the folder? Do they always have the same names?

At the most basic level you could do something like this:

do {

while ((Get-ChildItem E:\Temp\Files\ProductEngineCache).Count -lt 8)

Write-Host 'Resetting IIS'

The while condition will be continually evaluated until the file count reaches eight, at which point the next command will run.

thank you so much for reply, greatly appreciated,

8 files ONLY and always have same names and same file extension(s) 6 x .bin files and 2 .txt

OK, if they always have the same names, you could refine it a bit to ensure you’re checking only for those specific files:

$filesToWaitFor = @(

do {}

while ((Test-Path $filesToWaitFor) -contains $false)