Get Cloud PCs with Graph API - Forbidden

AxelC 51 Reputation points
2022-06-20T19:37:05.237+00:00

Hello,

I have an issue getting a list of Cloud PCs in my tenant using the Graph API.
I use an app registration, this app has the CloudPC.Read.All permission with admin consent. I initialize the connection with the following code

$Body = @{  
    Grant_Type    = "client_credentials"  
    Scope         = "https://graph.microsoft.com/.default"  
    client_Id     = $ApplicationID  
    Client_Secret = $AccessSecret  
    }  
  
$Connection = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$($TenantID)/oauth2/v2.0/token" -Method POST -Body $Body  
$Token = $Connection.access_token  
  
Connect-MgGraph -AccessToken $Token  
  
Select-MgProfile -Name beta  

I verify the scopes using the Cmdlet Get-MgContext, and can see that the CloudPC.Read.All well applies to the connection.

213027-image.png

Therefore, when trying to get a list of Cloud PCs using the Cmdlet Get-MgDeviceManagementVirtualEndpointCloudPC, I get a Forbidden error.

213123-image.png

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,590 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 36,896 Reputation points
    2022-06-21T10:10:26.067+00:00

    Hi @AxelC

    Do you have a Windows 365 license? https://learn.microsoft.com/en-us/graph/api/resources/cloudpc-api-overview?view=graph-rest-beta.

    Using the Microsoft Graph API for Cloud PCs requires an active Windows 365 license for the organization. Currently, Microsoft Graph API is available for Windows 365 Enterprise and not Windows 365 Business.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Manu Philip 16,971 Reputation points MVP
    2022-06-20T20:33:05.737+00:00

    It could be a syntax issue. Use Get-MgDeviceManagementVirtualEndpointCloudPC | fl or Get-MgDeviceManagementVirtualEndpointCloudPC -CloudPCId $cloudPCId

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--