microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Set-MgDriveItemContent uses incorrectly formatted graph end ppoint

Open
#3,772 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage type:bug
Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

Describe the bug

I am using Set-MgDriveItemContent to upload a small test text document. It fails with the error:
Entity only allows writes with a JSON Content-Type header.

When running the command with the -Debug flag, I can see the absolute url that is using:

DEBUG: Content type text/plain
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://graph.microsoft.com/v1.0/drives/b%21kA4oNtZbvEKpPLsSjEJ7S4dfN9wGhCpAhUgEYHvSBfKhADBMk4wiQ519UTHUsHC6/items/root%3A%2Fresults-12.txt/content

The url ends with /content but per the documentation, it should end with :/content

Expected behavior

Using Invoke-MgGraphRequest and a properly edited url, the upload works:

https://graph.microsoft.com/v1.0/drives/b!kA4oXXXXXPLsSjEJ7S4dfN9wGhCpAhUgEYHvSBfKhADBMk4wiQ519UTHUsHC6/items/root:/results-12.txt:/content

Name Value


size 80
webUrl https://contoso.sharepoint.com/sites/o365/LicenseProcessResults/results-12.txt
cTag "c:{8567605F-7A07-491F-8473-C8D249B50820},1"
file {[mimeType, text/plain], [hashes, System.Collections.Hashtable]}
@odata.context https://graph.microsoft.com/v1.0/$metadata#drives('b%21kA4oNtZbXXXXLsSjEJ7S4dfN9wGhCpAhUgEYHv…
parentReference {[siteId, 36280e90-5bd6-42bc-a93c-bb128c427b4b], [driveType, documentLibrary], [driveId, b!kA4…
lastModifiedBy {[application, System.Collections.Hashtable], [user, System.Collections.Hashtable]}
id 016IHMIYS7MBTYKB32D5EYI46I2JE3KCBA
isAuthoritative False
eTag "{8567605F-7A07-491F-8473-C8D249B50820},1"
createdBy {[application, System.Collections.Hashtable], [user, System.Collections.Hashtable]}
name results-12.txt
shared {[scope, users]}
fileSystemInfo {[createdDateTime, 9/15/2026 2:24:13 PM], [lastModifiedDateTime, 9/15/2026 2:24:13 PM]}
@microsoft.graph.downloadUrl https://contoso.sharepoint.com/sites/o365/_layouts/15/download.aspx?UniqueId=8567605f-7a07-491f-…
lastModifiedDateTime 9/15/2026 2:24:13 PM
createdDateTime 9/15/2026 2:24:13 PM

How to reproduce

$drive = ... #set to the value of a drive in a SharePoint or Onedrive site
$uploadParams = @{
'DriveId' = $drive.Id
'DriveItemId' = 'root:/some-file-name.txt
'InFile' = "$PSScriptRoot\sample.txt" #just create a small file with some sample text
'ContentType' = 'text/plain'
'Debug' = $true
}

Set-MgDriveItemContent @uploadParams

SDK Version

2.39.0

Latest version known to work for scenario above?

No response

Known Workarounds

Use Invoke-MgGraphRequest to manually construct the url of the graph to communicate with

Debug output
Click to expand log ```

DEBUG: [CmdletBeginProcessing]: - Set-MgDriveItemContent begin processing with parameterSet 'Set'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [AccessReview.Read.All, AccessReview.ReadWrite.All, AccessReview.ReadWrite.Membership, Application.Read.All, Application.ReadWrite.All, AppRoleAssignment.ReadWrite.All, AuditLog.Read.All, AuditLogsQuery.Read.All, Bookings.Read.All, ChannelMessage.ReadWrite, ChannelSettings.Read.All, DelegatedPermissionGrant.Read.All, DelegatedPermissionGrant.ReadWrite.All, Device.Read.All, DeviceManagementManagedDevices.Read.All, Directory.Read.All, Directory.ReadWrite.All, email, ExternalItem.Read.All, Files.Read, Group.Read.All, Group.ReadWrite.All, GroupMember.Read.All, IdentityRiskEvent.Read.All, OnPremDirectorySynchronization.Read.All, openid, Organization.Read.All, Policy.Read.All, Policy.ReadWrite.ApplicationConfiguration, PrivilegedAccess.Read.AzureAD, PrivilegedAccess.Read.AzureADGroup, PrivilegedAssignmentSchedule.Read.AzureADGroup, PrivilegedEligibilitySchedule.Read.AzureADGroup, profile, RoleManagement.Read.Directory, RoleManagement.ReadWrite.Directory, Sites.FullControl.All, Team.ReadBasic.All, TeamMember.Read.All, TeamworkDevice.Read.All, TeamworkTag.ReadWrite, User.Read, User.Read.All, User.ReadBasic.All, User.ReadWrite.All, UserAuthenticationMethod.Read.All].
DEBUG: Content type text/plain
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://graph.microsoft.com/v1.0/drives/b%21kA4oNtZbvEKpPLsSjEJ7S4dfN9wGhCpAhUgEYHvSBfKhADBMk4wiQ519UTHUsHC6/items/root%3A%2Fresults-55.txt/content

Headers:
FeatureFlag : 00000003
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.26100; en-US),PowerShell/7.6.5
SdkVersion : graph-powershell/2.39.0
client-request-id : 30e376a5-b08b-4c52-93df-524861239763
Accept-Encoding : gzip,deflate

Body:
This is a test upload file created at 09/14/2026 18:04:57
105
Mark was here.

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

Status Code:
BadRequest

Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : fa1da99e-e33b-43f5-bdb7-ca5b83de0399
client-request-id : 30e376a5-b08b-4c52-93df-524861239763
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Central US","Slice":"E","Ring":"4","ScaleUnit":"004","RoleInstance":"DS2PEPF00003844"}}
Date : Tue, 15 Sep 2026 14:29:54 GMT

Body:
{
"error": {
"code": "BadRequest",
"message": "Entity only allows writes with a JSON Content-Type header.",
"innerError": {
"date": "2026-09-15T14:29:55",
"request-id": "fa1da99e-e33b-43f5-bdb7-ca5b83de0399",
"client-request-id": "30e376a5-b08b-4c52-93df-524861239763"
}
}
}

</details>


### Configuration

Windows 11 x64

$PSVersionTable

Name Value


PSVersion 7.6.5
PSEdition Core
GitCommitId 7.6.5
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0


### Other information

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Set-MgDriveItemContent entry point and reproduce the issue with the provided uploadParams and Debug output. Trace how the DriveItemId is placed into the Graph URL, then verify the resulting endpoint preserves the documented :/content delimiters and that the text upload succeeds without the JSON Content-Type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.