Why Does My PowerShell Script Show Progress Without Using Write-Progress?
Asked by
CuriousCoder42
I'm running a PowerShell script that doesn't call `Write-Progress`, yet I occasionally see a progress flash during its execution. The script uses `Remove-Item` once, and I found that it supports the `-ProgressAction` parameter. I used `-ProgressAction SilentlyContinue` with `Remove-Item`, which stopped the progress flash, but I'm curious about `Copy-Item`, as it doesn't seem to trigger any progress indication. How can I know which cmdlets report progress and which don't?
Answers
It sounds like you're in a bit of a confusing situation with cmdlets and progress reporting! I recommend using `Start-Transcript` to log your script's output, which can give you more insight into what's happening. When dealing with `Copy-Item`, try wrapping it in a script block with `Invoke-Command` or run it with the `-Verbose` flag to get more information on its execution. And don't forget to wrap up with `Stop-Transcript` if youโre logging!
Reply to this answer
`Write-Progress` is a separate cmdlet that you need to call to visually show progress. It's not automatically linked to other cmdlets like `Copy-Item`. Unfortunately, some cmdlets, including `Copy-Item`, don't provide any built-in progress reporting, and the documentation can be a bit sparse. You just have to check the docs for each cmdlet individually to see if they support progress reporting or not.
Reply to this answer
To troubleshoot more effectively, consider adding breakpoints in your script or using `Out-Null` to suppress output. It can clarify which command is causing unexpected behavior. Also, check if any modules or previous scripts loaded in your profile might affect things. Good luck!
Reply to this answer
Just a heads-up, `Remove-Item` added a progress indicator in PowerShell v7.5, and `Copy-Item` in v7.4, so make sure your version is up to date as that can be a factor. If you're not seeing progress with `Copy-Item`, it might just be one of those cmdlets that doesnโt have a visual representation of progress in older versions. Use `$ProgressPreference` to suppress progress output globally if all you want is clean output.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions