Hi together,<\/p>\n
How can I make a countdown that shows how much time remains until the $Time (next backup) is made?<\/p>\n
For example the every 30 minutes the script tests if a change was made then make a backup or not I would like to see how many minutes it takes to make the next test.<\/p>\n
timer should be here at \" $Timer \": Write-Host “no change - test number = [$($i)] $DateFormatSystem $Timer Thanks for any help!<\/p>\n Hi together,<\/p>\n How can I make a countdown that shows how much time remains until the $Time (next backup) is made?<\/p>\n For example the every 30 minutes the script tests if a change was made then make a backup or not I would like to see how many minutes it takes to make the next test.<\/p>\n timer should be here at \" $Timer \": Write-Host “no change - test number = [$($i)] $DateFormatSystem $Timer Thanks for any help!<\/p>\n Something like this?<\/p>\n Hi,<\/p>\n it is not exaclty what I wanted but it works. The timer should not be like in a window or so.<\/p>\n It should be here at the end: < Write-Host \"No change was made - loop number = [$($i)] Time for the next test (backup): (Here should be the time) \" ><\/p>\n thanks for your help!<\/p>","upvoteCount":0,"datePublished":"2020-11-29T12:00:52.000Z","url":"https://community.spiceworks.com/t/powershell-how-to-make-a-countdown/783160/3","author":{"@type":"Person","name":"spiceuser-idbhl","url":"https://community.spiceworks.com/u/spiceuser-idbhl"}},{"@type":"Answer","text":" Hello again,<\/p>\n I did it but now I have another problem.<\/p>\n The problem is that it adds a zero after the number when it goes down.<\/p>\n Output:<\/p>\n 11<\/p>\n 10<\/p>\n 90<\/p>\n 80<\/p>\n 70<\/p>\n …<\/p>\n How can I let it count down without the zero?<\/p>\n Thanks for help!<\/p>","upvoteCount":0,"datePublished":"2020-11-29T19:55:56.000Z","url":"https://community.spiceworks.com/t/powershell-how-to-make-a-countdown/783160/4","author":{"@type":"Person","name":"spiceuser-idbhl","url":"https://community.spiceworks.com/u/spiceuser-idbhl"}},{"@type":"Answer","text":" Add some spaces after n<\/code>n”<\/p>\n
for ($i = 1; $i -lt 5001; $i++) {\n\n# This does not work\n$Timer = ($Time /60) \nfor ($Timer = 30; $Timer -gt 0; $Timer--) {\n Write-Host -NoNewLine \"`r$Timer\"\n Start-Sleep -Milliseconds 1000\n}\nWrite-Host #ends the line after loop\n\n $Now = Get-Date -Format $DateFormat\n $DateFormatSystem = Get-Date -Format \"(dd.MM.yyyy HH:mm:ss)\"\n $Folder = Join-Path -Path $Destination -ChildPath ($Now + (Split-Path -Path $FolderName -Leaf))\n if (Get-ChildItem -Path $Source -Recurse -Force | Where-Object { $_.Attributes -match 'Archive' }) {\n Write-Host \"Backup made - test number = ($($i)) $DateFormatSystem`n`n\" -ForegroundColor Green\n robocopy $Source $Folder /E /XC /XN /XO \n Push-Location -Path $Source\n attrib -A /S /D \n Pop-Location\n } else {\n Write-Host \"no change - test number = [$($i)] $DateFormatSystem $Timer`n`n\" -ForegroundColor Red\n } \n Start-Sleep -Seconds $Time\n}\n<\/code><\/pre>","upvoteCount":4,"answerCount":5,"datePublished":"2020-11-28T20:23:13.000Z","author":{"@type":"Person","name":"spiceuser-idbhl","url":"https://community.spiceworks.com/u/spiceuser-idbhl"},"suggestedAnswer":[{"@type":"Answer","text":"
n<\/code>n”<\/p>\n
for ($i = 1; $i -lt 5001; $i++) {\n\n# This does not work\n$Timer = ($Time /60) \nfor ($Timer = 30; $Timer -gt 0; $Timer--) {\n Write-Host -NoNewLine \"`r$Timer\"\n Start-Sleep -Milliseconds 1000\n}\nWrite-Host #ends the line after loop\n\n $Now = Get-Date -Format $DateFormat\n $DateFormatSystem = Get-Date -Format \"(dd.MM.yyyy HH:mm:ss)\"\n $Folder = Join-Path -Path $Destination -ChildPath ($Now + (Split-Path -Path $FolderName -Leaf))\n if (Get-ChildItem -Path $Source -Recurse -Force | Where-Object { $_.Attributes -match 'Archive' }) {\n Write-Host \"Backup made - test number = ($($i)) $DateFormatSystem`n`n\" -ForegroundColor Green\n robocopy $Source $Folder /E /XC /XN /XO \n Push-Location -Path $Source\n attrib -A /S /D \n Pop-Location\n } else {\n Write-Host \"no change - test number = [$($i)] $DateFormatSystem $Timer`n`n\" -ForegroundColor Red\n } \n Start-Sleep -Seconds $Time\n}\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2020-11-28T20:23:13.000Z","url":"https://community.spiceworks.com/t/powershell-how-to-make-a-countdown/783160/1","author":{"@type":"Person","name":"spiceuser-idbhl","url":"https://community.spiceworks.com/u/spiceuser-idbhl"}},{"@type":"Answer","text":"
# How long to wait between processes in Minutes\n$Time = 5\n\nfor ($i = 1; $i -lt 5001; $i++) {\n\n# This does not work\n# $Timer = ($Time /60) \n\nfor ($Timer = $Time*60; $Timer -gt 0; $Timer--) {\n $Endtime = Get-date\n $Endtime = ($Endtime.AddSeconds($timer)).ToShortTimeString()\n # Write-Host -NoNewLine \"`r$Timer $Endtime\"\n Start-Sleep -Milliseconds 1000\n Write-Progress -Activity \"Backup\" -Status \"Waiting for next window at $Endtime\" -PercentComplete -1 -SecondsRemaining $Timer\n}\nWrite-Progress -Completed -Activity \"Backup\" -Status \"Waiting for next window at $Endtime\" -PercentComplete -1 -SecondsRemaining $Timer\n# Write-Host #ends the line after loop\n\n $Now = Get-Date -Format $DateFormat\n $DateFormatSystem = Get-Date -Format \"(dd.MM.yyyy HH:mm:ss)\"\n\n $Folder = Join-Path -Path $Destination -ChildPath ($Now + (Split-Path -Path $FolderName -Leaf))\n if (Get-ChildItem -Path $Source -Recurse -Force | Where-Object { $_.Attributes -match 'Archive' }) {\n Write-Host \"Backup made - test number = ($($i)) $DateFormatSystem`n`n\" -ForegroundColor Green\n robocopy $Source $Folder /E /XC /XN /XO \n Push-Location -Path $Source\n attrib -A /S /D \n Pop-Location\n } else {\n Write-Host \"no change - test number = [$($i)] $DateFormatSystem $Timer`n`n\" -ForegroundColor Red\n } \n\n # the next line will cause to pause for $time seconds here \n # Remove this line as it will stop your waiting process from running up above.\n # Start-Sleep -Seconds $Time\n\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-11-29T02:04:45.000Z","url":"https://community.spiceworks.com/t/powershell-how-to-make-a-countdown/783160/2","author":{"@type":"Person","name":"fids74gf","url":"https://community.spiceworks.com/u/fids74gf"}},{"@type":"Answer","text":"
$Time = 11\n for ($Timer = $Time; $Timer -gt 0; $Timer--) {\n Write-Host \"`rNo change was made - loop number = ($($i)) - Next check in: $Timer\" -NoNewLine -ForegroundColor Red\n Start-Sleep -Milliseconds 1000\n }\n Write-Host \"`rNo change was made - loop number = ($($i)) - Next check in: $Timer\" -ForegroundColor Red \n } \n<\/code><\/pre>\n
$Timer\"<\/code> so like $Timer \". The new string is not overwriting the number from the previous string.<\/p>\n
$Time = 11\n for ($Timer = $Time; $Timer -gt 0; $Timer--) {\n Write-Host \"`rNo change was made - loop number = ($($i)) - Next check in: $Timer \" -NoNewLine -ForegroundColor Red\n Start-Sleep -Milliseconds 1000\n }\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-11-30T03:33:58.000Z","url":"https://community.spiceworks.com/t/powershell-how-to-make-a-countdown/783160/5","author":{"@type":"Person","name":"fids74gf","url":"https://community.spiceworks.com/u/fids74gf"}}]}}