msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Set-MgDriveItemContent doesn't work with Azure Automation 7.2 runbook
Describe the bug
I created an Azure Automation PowerShell 7.2 runbook to add a file to a SharePoint site. The Microsoft.Graph.Files module (7.2) is loaded as a resource into the automation account. The runbook authenticates with a managed identity and can successfully use other SharePoint cmdlets like Get-MgSiteDrive and Get-MgSite for the target site, so we know that SDK cmdlets work for the target site. However, when the runbook attempts to run Set-MgDriveItemContent, the error is that the cmdlet cannot be found.
The same command works perfectly with an interactive Graph SDK session (delegated and app-only).
$NewFile = Set-MgDriveItemContent -DriveId $DocumentsDrive.Id -DriveItemId $TargetFile -InFile $File
The Graph API PUT request works perfectly too.
$Uri = ("https://graph.microsoft.com/V1.0/sites/{0}/drive/items/root:/General/{1}:/content" -f $Site.Id, $ExcelOutputFile) $NewFile = Invoke-MgGraphRequest -uri $uri -Method PUT -InputFilePath $ExcelOutputFile
Expected behavior
I expect the cmdlet to be available in an Azure Automation runbook when the module is loaded into the automation account.
How to reproduce
Create an automation account. Add the necessary Graph SDK modules, including Microsoft.Graph.Files as account resources Create a runbook with some code to authenticate using a managed identity and then upload a file to SharePoint with Set-MgDriveFileItemContent. Here's some example code.
$SiteUri = "https://office365itpros.sharepoint.com/sites/Office365Adoption" $SiteId = $SiteUri.Split('//')[1].split("/")[0] + ":/sites/" + $SiteUri.Split('//')[1].split("/")[2] $Site = Get-MgSite -SiteId $SiteId If (!$Site) { Write-Output ("Unable to connect to site {0} with id {1}" -f $Uri, $SiteId) Exit } [array]$Drives = Get-MgSiteDrive -SiteId $Site.Id $DocumentsDrive = $Drives | Where-Object {$_.Name -eq "Documents"} $TargetFile = "root:/General/" + $ExcelOutputFile + ":"
$NewFile = Set-MgDriveItemContent -DriveId $DocumentsDrive.Id -DriveItemId $TargetFile -InFile $File
SDK Version
2.25
Latest version known to work for scenario above?
Unknown
Known Workarounds
Use the Graph API request instead.
Debug output
Runs in Azure Automation and as the cmdlet can't be found, no debug can be output
Configuration
No response
Other information
No response
Azure Automation is capped at PowerShell 7.2 which is built upon dotnet 6 which is officially out of support since Nov 12th 2024 🤔
I cannot believe they still don't provide PowerShell 7.4 (dotnet8) for Azure Automation....
Related to #3151
The release notes for SDK V2.26 https://github.com/microsoftgraph/msgraph-sdk-powershell/releases says that V2.26 Drops unsupported net 6 and net 7 in #3078https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/3078
From: Stephan van Rooij @.> Sent: Friday, February 21, 2025 8:19 PM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: 12 Knocksinna (Gmail) @.>; Author @.> Subject: Re: [microsoftgraph/msgraph-sdk-powershell] Set-MgDriveItemContent doesn't work with Azure Automation 7.2 runbook (Issue #3112)
Azure Automation is capped at PowerShell 7.2 which is built upon dotnet 6 which is officially out of support since Nov 12th 2024 🤔
I cannot believe they still don't provide PowerShell 7.4 (dotnet8) for Azure Automation....
Related to #3151https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3151
— Reply to this email directly, view it on GitHubhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3112#issuecomment-2675463928, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK45CIQUO5F5WUVLDKE6WGT2Q6C4RAVCNFSM6AAAAABWXVMGLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZVGQ3DGOJSHA. You are receiving this because you authored the thread.Message ID: @.@.>> [svrooij]svrooij left a comment (microsoftgraph/msgraph-sdk-powershell#3112)https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3112#issuecomment-2675463928
Azure Automation is capped at PowerShell 7.2 which is built upon dotnet 6 which is officially out of support since Nov 12th 2024 🤔
I cannot believe they still don't provide PowerShell 7.4 (dotnet8) for Azure Automation....
Related to #3151https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3151
— Reply to this email directly, view it on GitHubhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3112#issuecomment-2675463928, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK45CIQUO5F5WUVLDKE6WGT2Q6C4RAVCNFSM6AAAAABWXVMGLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZVGQ3DGOJSHA. You are receiving this because you authored the thread.Message ID: @.@.>>