Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-MgDriveItemContent doesn't work with Azure Automation 7.2 runbook #3112

Open
12Knocksinna opened this issue Feb 8, 2025 · 2 comments
Open

Comments

@12Knocksinna
Copy link

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.

Image

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

@12Knocksinna 12Knocksinna added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 8, 2025
@svrooij
Copy link

svrooij commented Feb 21, 2025

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

@12Knocksinna
Copy link
Author

12Knocksinna commented Feb 22, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants