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
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).
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 + ":"
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
The text was updated successfully, but these errors were encountered: