You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to upload files to OneDrive Useing New-MgDriveItem -DriveId "" -Name "test.csv" -FileMimeType "text/csv" -ContentInputFile "C:\example.csv" and receive following error
The property 'content' does not exist on type 'oneDrive.item'. Make sure to only use property names that are
defined by the type. AB#7438
I'm trying to upload a CSV to OneDrive using New-MgDriveItem -DriveId "b!lHY...ZZ" -Name "test.csv" -ContentInputFile "C:\Temp\test.csv" and I'm seeing the error:
As for /sites/{site-id}/drive/items/root:/{name-of-file.ext}:/content, the path is currently missing in the OpenAPI document used to generate the module. I've opened an issue in the metadata repo for a fix - microsoftgraph/msgraph-metadata#238.
Ah, it was a missing :
❌ -DriveItemId "root:/myfile.txt"
✅ -DriveItemId "root:/myfile.txt:"
Super easy to miss. FWIW, for a time I was confused by the parameter name (-DriveItemId as it'd suggest needing the id of something in existence) but I appreciate the difficulty in naming things when it comes to determining file names, file paths, and complete paths.
[DriveItemId <String>]: key: id of driveItemon the docs doesn't aid understanding. Examples would be nice too 🙏🏼
I really can't tell if Set-MgDriveItemContent is meant for use with New-MgDriveItemUploadSession, or if they are each their own entire thing. The parameters for New-MgDriveItemUploadSession have me wishfully thinking that it is a one-stop-shop cmdlet and that I can provide my item to the -Item parameter.
@mikewoodd3432 thanks for that and yes, exactly that. I just so happened to be looking into this this week and came to realize that's the way to 'feed' the data. That link will come in handy for reference for sure, thanks again.
I got a file uploaded to SharePoint JeremyTBradshaw (throughput was slow....)
I used New-MgDriveItemChild to create an empty item in a drive folder (New-MgDriveItem would be similar)
# tell the method I want a file item, by providing an empty IMicrosoftGraphFile structure for the -File parameter
$IMicrosoftGraphFile = @{
hashes = ""
mimeType = ""
}
# create the new file item
$newitem = New-MgDriveItemChild -DriveId $drive.Id -DriveItemId $drivefolder.Id -Name $uploadFilePath -File $IMicrosoftGraphFile
Then used $driveUploadSession as per the Invoke-WebRequest method as per web link I mentioned previously.
# create the upload session
$driveUploadSession = New-MgDriveItemUploadSession -DriveId $drive.Id -DriveItemId $newitem.Id
That's what worked for me. Courtesy of GitHub Copilot. 😊
# Connect to Microsoft GraphConnect-MgGraph-TenantId $tenantId-ClientId $appId-Scopes "Files.ReadWrite.All"# SharePoint Drive Id (Document Library)$driveId=""# File to upload$filePath="C:\Temp\test.csv"$fileProperties=Get-ChildItem-Path $filePath# Read the file content as a byte array$fileContent= [System.IO.File]::ReadAllBytes($filePath)
# Destination file name$destinationName="$($fileProperties.BaseName)-$(Get-Date-Format "yyyy-MM-dd HH-mm-ss")$($fileProperties.Extension)"# Upload the file to SharePointInvoke-MgGraphRequest-Method PUT -Uri "https://graph.microsoft.com/v1.0/drives/$driveId/root:/IntuneHashes/$destinationName`:/content"-Body $fileContent-ContentType "application/octet-stream"
That's what worked for me. Courtesy of GitHub Copilot. 😊
# Connect to Microsoft GraphConnect-MgGraph-TenantId $tenantId-ClientId $appId-Scopes "Files.ReadWrite.All"# SharePoint Drive Id (Document Library)$driveId=""# File to upload$filePath="C:\Temp\test.csv"$fileProperties=Get-ChildItem-Path $filePath# Read the file content as a byte array$fileContent= [System.IO.File]::ReadAllBytes($filePath)
# Destination file name$destinationName="$($fileProperties.BaseName)-$(Get-Date-Format "yyyy-MM-dd HH-mm-ss")$($fileProperties.Extension)"# Upload the file to SharePointInvoke-MgGraphRequest-Method PUT -Uri "https://graph.microsoft.com/v1.0/drives/$driveId/root:/IntuneHashes/$destinationName`:/content"-Body $fileContent-ContentType "application/octet-stream"
Thanks a lot for your script. It works for my case
Activity
darrelmiller commentedon Mar 17, 2020
Unfortunately this is one of those commands that is a little "different" and the autogeneration fails to do the right thing. It will need some love.
darrelmiller commentedon Aug 12, 2020
Related to #54
Spence10873 commentedon Apr 11, 2022
I'm trying to upload a CSV to OneDrive using New-MgDriveItem -DriveId "b!lHY...ZZ" -Name "test.csv" -ContentInputFile "C:\Temp\test.csv" and I'm seeing the error:

vandeyv commentedon Oct 4, 2022
same issue here, is there a solution or workaround?
joshtransient commentedon Nov 15, 2022
Workaround for small files under 4MB:
For a SPO site's default document library:
Large upload session is a different story. Maybe after 2.5 years, finally time to show these cmdlets "some love"?
peombwa commentedon Dec 21, 2022
Uploading new/existing files to OneDrive is already supported via
Set-MgDriveItemContent:See #433.
As for
/sites/{site-id}/drive/items/root:/{name-of-file.ext}:/content, the path is currently missing in the OpenAPI document used to generate the module. I've opened an issue in the metadata repo for a fix - microsoftgraph/msgraph-metadata#238.robinmalik commentedon Jan 16, 2023
Two things to report
Set-MgDriveItemContent : Entity only allows writes with a JSON Content-Type header.... when using:
Though I could absolutely be doing something wrong here. I've failed to find anything online to help with this, so clutching at straws.
New-MgDriveItemis so big that it basically hung my browser for at least 30 seconds 😶I'm using
Microsoft.Graph.Filesversion1.20.robinmalik commentedon Jan 16, 2023
Ah, it was a missing
:❌
-DriveItemId "root:/myfile.txt"✅
-DriveItemId "root:/myfile.txt:"Super easy to miss. FWIW, for a time I was confused by the parameter name (
-DriveItemIdas it'd suggest needing the id of something in existence) but I appreciate the difficulty in naming things when it comes to determining file names, file paths, and complete paths.[DriveItemId <String>]: key: id of driveItemon the docs doesn't aid understanding. Examples would be nice too 🙏🏼JeremyTBradshaw commentedon Mar 27, 2023
robinmalik Peter Ombwa (@peombwa) Hi guys. I don't suppose you could share some layman's terms level tips for using the large/resumable upload sessions? I find New-MgDriveItemUploadSession, but nothing else that obviously goes with it.
I really can't tell if Set-MgDriveItemContent is meant for use with New-MgDriveItemUploadSession, or if they are each their own entire thing. The parameters for New-MgDriveItemUploadSession have me wishfully thinking that it is a one-stop-shop cmdlet and that I can provide my item to the -Item parameter.
Any guidance will be much appreciated.
mikew3432 commentedon Jun 11, 2023
JeremyTBradshaw are we meant to use Invoke-WebRequest? this is how I see it done here... (ref. the last several lines of code)
JeremyTBradshaw commentedon Jun 11, 2023
@mikewoodd3432 thanks for that and yes, exactly that. I just so happened to be looking into this this week and came to realize that's the way to 'feed' the data. That link will come in handy for reference for sure, thanks again.
mikew3432 commentedon Jun 14, 2023
I got a file uploaded to SharePoint JeremyTBradshaw (throughput was slow....)
I used New-MgDriveItemChild to create an empty item in a drive folder (New-MgDriveItem would be similar)
# tell the method I want a file item, by providing an empty IMicrosoftGraphFile structure for the -File parameter
$IMicrosoftGraphFile = @{
hashes = ""
mimeType = ""
}
# create the new file item
$newitem = New-MgDriveItemChild -DriveId $drive.Id -DriveItemId $drivefolder.Id -Name $uploadFilePath -File $IMicrosoftGraphFile
Then used $driveUploadSession as per the Invoke-WebRequest method as per web link I mentioned previously.
# create the upload session
$driveUploadSession = New-MgDriveItemUploadSession -DriveId $drive.Id -DriveItemId $newitem.Id
JeremyTBradshaw commentedon Jun 14, 2023
Thanks @mikewoodd3432 . Glad to see live human confirmation that it works. I plan to use this stuff in this script: https://github.com/JeremyTBradshaw/PowerShell/blob/main/Export-MSGraphMailbox.ps1
Just waiting for the right level of business in my day to day to really tackle it, hopefully soon.
mozziemozz commentedon Nov 30, 2023
That's what worked for me. Courtesy of GitHub Copilot. 😊
thanhgp-oucru commentedon Nov 28, 2024
Thanks a lot for your script. It works for my case