msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

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

Open gjhardie opened this issue 1 year ago • 8 comments

Describe the bug

I'm trying to down load a file from SharePoint using Get-MgDriveItemContent. This has worked previously without an error.
I've had to change environment by way of running this code on Windows Server 2022...previously Windows Server 2016
Now I get this:

Get-MgDriveItemContent_Get: <script name>.ps1:1273:13
Line |
1273 |              Get-MgDriveItemContent -DriveId $fileItem.parentReference …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value') Actual value was 2147483647.

Expected behavior

Completes without:

Get-MgDriveItemContent_Get: <script name>.ps1:1273:13
Line |
1273 |              Get-MgDriveItemContent -DriveId $fileItem.parentReference …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value') Actual value was 2147483647.

How to reproduce

$accConfFileList = get-FolderFileItemList $SiteURL $newSPInputFolder
foreach ($fileItem in ($accConfFileList)) {
    Get-MgDriveItemContent -DriveId $fileItem.parentReference.driveId -DriveItemId $fileItem.id -OutFile "$inputFilePath"
}

``

SDK Version

2.25.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

DEBUG: [CmdletBeginProcessing]: - Get-MgDriveItemContent begin processing with parameterSet 'Get'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientSecret', ContextScope: 'Process', AppName: 'Redacted'.
DEBUG: [Authentication]: - Scopes: [Files.ReadWrite.AppFolder, DeviceManagementManagedDevices.Read.All, Group.Read.All, Files.SelectedOperations.Selected, Sites.Read.All, DeviceManagementServiceConfig.Read.All, Sites.ReadWrite.All, Sites.Manage.All, Directory.Read.All, DeviceManagementRBAC.Read.All, Files.Read.All, DeviceManagementConfiguration.Read.All, Lists.SelectedOperations.Selected].
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method: GET

Absolute Uri: <Redacted>

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.20348; en-GB),PowerShell/2025.0.0
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell/2.25.0,
client-request-id             : <Redacted>

Body: <Redacted>

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : private
Accept-Ranges                 : bytes
ETag                          : "{4EAB61C4-39C7-427E-97FF-C176C44AC10B},2"
P3P                           : CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
X-NetworkStatistics           : 0,1573888,0,0,4710826,0,1573888,7
X-SharePointHealthScore       : 3
docID                         : <Redacted>
X-Download-Options            : noopen
CTag                          : {4EAB61C4-39C7-427E-97FF-C176C44AC10B},2,4
X-AspNet-Version              : 4.0.30319
IsOCDI                        : 0
X-DataBoundary                : EU
X-1DSCollectorUrl             : https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/
X-AriaCollectorURL            : https://eu-mobile.events.data.microsoft.com/Collector/3.0
SPRequestGuid                 : <Redacted>
request-id                    : <Redacted>
MS-CV                         : <Redacted>
Alt-Svc                       : h3=":443"
Report-To                     : {"group":"network-errors","max_age":7200,"endpoints":[{"url":"<Redacted>"}]}
NEL                           : {"report_to":"network-errors","max_age":7200,"success_fraction":0.001,"failure_fraction":1.0}
Strict-Transport-Security     : max-age=31536000
X-Frame-Options               : SAMEORIGIN
Content-Security-Policy       : frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com teams.cloud.microsoft *.office365.com goals.cloud.microsoft *.powerapps.com *.powerbi.com *.yammer.com engage.cloud.microsoft word.cloud.microsoft excel.cloud.microsoft powerpoint.cloud.microsoft *.officeapps.live.com *.office.com *.microsoft365.com m365.cloud.microsoft *.cloud.microsoft *.stream.azure-test.net *.microsoftstream.com *.dynamics.com *.microsoft.com onedrive.live.com *.onedrive.live.com securebroker.sharepointonline.com;
X-Powered-By                  : ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.25715
X-Content-Type-Options        : nosniff
X-MS-InvokeApp                : 1; RequireReadOnly
X-Cache                       : CONFIG_NOCACHE
X-MSEdge-Ref                  : <Redacted>
Date                          : Wed, 05 Feb 2025 13:51:03 GMT

Body: <Redacted>

DEBUG: [CmdletException]: Received exception with message 'PSArgumentOutOfRangeException - Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value')
Actual value was 2147483647. :    at System.Management.Automation.ProgressRecord.set_PercentComplete(Int32 value)
   at Microsoft.Graph.PowerShell.PSCmdletExtensions.GetProgress(ProgressRecord currentProgressRecord, Stream stream)
   at Microsoft.Graph.PowerShell.PSCmdletExtensions.WriteToStream(PSCmdlet cmdlet, Stream inputStream, Stream outputStream, String downloadUrl, CancellationToken cancellationToken)
   at Microsoft.Graph.PowerShell.PSCmdletExtensions.WriteToFile(PSCmdlet cmdlet, HttpResponseMessage response, Stream inputStream, String filePath, CancellationToken cancellationToken)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgDriveItemContent_Get.on2Xx(HttpResponseMessage responseMessage, Task`1 response)
   at Microsoft.Graph.PowerShell.Files.DriveGetItemsContent_Call(HttpRequestMessage request, Func`3 on2Xx, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Files.DriveGetItemsContent_Call(HttpRequestMessage request, Func`3 on2Xx, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Files.DriveGetItemsContent(String driveId, String driveItemId, String Format, IDictionary headers, Func`3 on2Xx, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgDriveItemContent_Get.ProcessRecordAsync()'
Get-MgDriveItemContent_Get: <script name>.ps1:1273:13
Line |
1273 |              Get-MgDriveItemContent -DriveId $fileItem.parentReference …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot set percent because PercentComplete cannot be greater than 100. (Parameter 'value') Actual value was 2147483647.
DEBUG: [CmdletEndProcessing]: - Get-MgDriveItemContent end processing.
$_.ScriptStackTrace
at Get-MgDriveItemContent<Process>, C:\Program Files\PowerShell\Modules\Microsoft.Graph.Files\2.25.0\exports\ProxyCmdletDefinitions.ps1: line 6632

Configuration

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.20348
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

gjhardie avatar Feb 05 '25 15:02 gjhardie

Hi @gjhardie I think this is more of an environment issue than an SDK issue. You can try adding $ProgressPreference = "SilentlyContinue" in your script and ensure that your server is up to date because some builds may be having PowerShell related bugs

timayabi2020 avatar Feb 05 '25 16:02 timayabi2020

Hi @timayabi2020, Thanks for your response. With environment issue could you be more specific. All $ProgressPreference = "SilentlyContinue" is doing is masking progress functionality that should be working in the command and clearly isn't. The file still gets downloaded. Why did you add area: PowerShell 5.1, when the version in use is 7.5.0?

gjhardie avatar Feb 05 '25 20:02 gjhardie

This problem is not resolved as:

1. $ProgressPreference = "SilentlyContinue" just masks the issue and stops progress functionality. 2. From an environment perspective the latest versions of PowerShell, SDK, VS Code & OS are being used.

gjhardie avatar Feb 06 '25 11:02 gjhardie

I am experiencing the same issue, seemingly out of nowhere. I did update to PowerShell 7.5.0 recently on both systems in question, so it could be related to that. Also, I had tried setting the -ProgressAction swtich to SilentlyContinue, and it didn't seem to help; neither did setting the $ProgressPreference variable. This is happening on our automation server, which is running Windows 2019 Server Datacenter, and my development system which is running Windows 2016 Server Standard.

MichaelPhillipsPS avatar Mar 10 '25 17:03 MichaelPhillipsPS

I am also experiencing this issue. The workaround setting -ProgressAction "SilentlyContinue" does work on my Windows 11 machine, but it still throws on the Debian machine which actually runs the code

Version 2.26.1 for the module.

A workaround I found. The file seems to download fully even though the Progress-tracking throws an error. Setting the -ErrorAction to Ignore and checking if the file has a size greater than 0 seems to be a workaround. Although not catching an actual error of downloading the file is a problem.

larsthelord avatar Apr 10 '25 21:04 larsthelord

I am also seeing this error in version 2.29.0. We do get a report produced but how can we confirm that the the data is exporting correctly?

dg-SCAT avatar Jul 16 '25 08:07 dg-SCAT

I am also having this issue.

I've currently used this code to manage the various symptoms:

$GraphUsers = Get-MgUser -Filter 'accountEnabled eq true' -All
foreach ($GraphUser in $GraphUsers) {
    $UserUPNSafe = $GraphUser.UserPrincipalName.Replace(".","_").Replace("@","_")

    try {
        Get-MgUserPhotoContent -UserId $GraphUser.Id -OutFile ".\$NewFolderName\$UserUPNSafe.jpg" -ErrorAction Stop
        Write-Host "Photo downloaded for $($GraphUser.DisplayName)"
    } catch {
        if ($_.FullyQualifiedErrorId -like "ImageNotFound*") {
            Write-Host "No photo exists for $($GraphUser.DisplayName)"
        } elseif ($_.Exception.Message -like "Cannot set percent because PercentComplete cannot be greater than 100*") {
            Write-Host "PercentComplete Error" -Fore Red #for current testing/tracking
            Write-Host "Photo downloaded for $($GraphUser.DisplayName)"
        } else {
            Write-Host "Error for $($GraphUser.DisplayName)" -Fore Red
            Write-Host $_ -Fore Red
        }
    }

    # Rate Limit Graph and Get-MgUserPhotoContent requests
    Start-Sleep -Seconds 3
}

PowerShell x64 7.5.2 or Windows PowerShell 5.1.17763.7553 Windows Server 2019 Standard or Windows 11 Enterprise 24H2 Microsoft.Graph.Authentication 2.29.1 Microsoft.Graph.Users 2.29.1

Get-MgUserPhotoContent by default displays Progress.

For Windows PowerShell 5.1: It does not support -ProgressAction. Setting $ProgressPreference to 'SilentlyContinue' has no effect, it continues to display a Progress.

Image

For PowerShell x64 7.5.2: It supports -ProgressAction and setting it to SilentlyContinue works to hide the Progress. Setting $ProgressPreference has no effect. And the PercentComplete error still occurs, although out of 44 errors, in 41 instances the file is created successfully, and in 3 instances the file is 0 bytes.

Image

In my opinion and experience, this seems to be a bug in Get-MgUserPhotoContent, where it by default shows Progress when it maybe shouldn't? Or it should honor $ProgressPreference? Also, the Progress it does show, it seems to not remove it after by using -Completed, causing multiple Progress to be shown at the same time. But furthermore, because it is trying to display Progress, even when controlling Progress as above, from the error it seems to be trying to assign the value 2147483647 to the -PercentComplete parameter.

I think this cmdlet should be expanded, to allow something such as -Wait to wait until download complete, before proceeding in code.

From my testing, adding Start-Sleep seems to have prevented this issue from occurring in 5.1, and seems to have reduced the instances for 7.5.2, meaning other's suspicions could be correct, causing multiple downloads / progress bars at the same time, or simply a connectivity / rate limit issue with Graph. I will experiment with the amount of seconds it pauses for.

Does anyone know a version of Microsoft.Graph.Users module that does not exhibit this behaviour?

systems-imei avatar Aug 05 '25 07:08 systems-imei

Having the same issues here.

Name Value


PSVersion 7.5.3 PSEdition Core GitCommitId 7.5.3 OS Microsoft Windows 10.0.20348 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

dsamson-pluscare avatar Sep 26 '25 07:09 dsamson-pluscare