Skip to content

Get-MgReport* Cmdlets give PercentComplete error when overwriting a file #3488

@npherson

Description

@npherson

Describe the bug

When running any of the Get-MgReport* cmdlets, such as Get-MgReportEmailActivityUserDetail, you will receive the following PercentComplete error if the outfile already exists (hiding the progress and warnings to minimize noise):

>Get-MgReportEmailActivityUserDetail -period D180 -outfile emailactivity2.csv -ProgressAction SilentlyContinue -WarningAction SilentlyContinue

Get-MgReportEmailActivityUserDetail_Get1: Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value')
Actual value was 2147483647.

Expected behavior

Get-MGReport* cmdlets should not run into the "Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value')" error when completing successfully and overwriting an outfile.

How to reproduce


Write-Host "Make sure the output file doesn't already exist..."
Remove-Item C:\Example\emailactivity.csv -ErrorAction SilentlyContinue

Write-Host "Run the report to create the output file..."
Get-MgReportEmailActivityUserDetail -period D180 -outfile C:\Example\emailactivity.csv -ProgressAction SilentlyContinue -WarningAction SilentlyContinue

Write-Host "Run the report to a second time where it has to overwrite the output file... it generates the error."
Get-MgReportEmailActivityUserDetail -period D180 -outfile C:\Example\emailactivity.csv -ProgressAction SilentlyContinue -WarningAction SilentlyContinue

Write-Host "Delete the output file so we can show the error goes away... Inconsistent results when we don't pause after the file deletion..."
Remove-Item C:\Example\emailactivity.csv
Start-Sleep 5

Write-Host "Run the report a third time to show the error goes away when it doesn't have to overwrite the output file..."
Get-MgReportEmailActivityUserDetail -period D180 -outfile C:\Example\emailactivity.csv -ProgressAction SilentlyContinue -WarningAction SilentlyContinue

SDK Version

No response

Latest version known to work for scenario above?

2.34.0

Known Workarounds

No response

Debug output

No test tenant and debug output is sensitive ```
</details>


### Configuration

- OS: Windows 11 24H2
- Arch:  x64

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions