Set-MgDriveItemContent uses incorrectly formatted graph end ppoint

Đang mở
#3,772 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
powershell
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu tại entry point Set-MgDriveItemContent và tái hiện sự cố với uploadParams được cung cấp cùng đầu ra Debug. Theo dõi cách DriveItemId được đặt vào Graph URL, sau đó xác minh rằng endpoint kết quả vẫn giữ các dấu phân cách :/content được ghi trong tài liệu và việc tải lên văn bản thành công mà không có lỗi JSON Content-Type.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status:waiting-for-triage type:bug
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_
Ngôn ngữ chính
C#
Star
898
Fork
230
Merge trung bình
2 ngày 5 giờ
Pull request đã merge (30 ngày)
31

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoftgraph/msgraph-sdk-powershell

Tất cả issue của microsoftgraph/msgraph-sdk-powershell

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.