How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API

How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API! Let’s list all the Microsoft 365 Cloud PCs in a Tenant using Microsoft Graph API. This article demonstrates how to automate the process of retrieving all Windows 365 Cloud PCs in a tenant using the Microsoft Graph API. Let’s learn together and simplify your work by automating as many GUI tasks as possible.

The Microsoft Graph API provides programmatic access to Cloud PC resources, enabling administrators to query information and perform management actions across their organization. These capabilities mirror the operations available through Microsoft Endpoint Manager, but with the added flexibility of automation and integration into custom workflows.

To leverage the Microsoft Graph API for Cloud PCs, your organization must hold an active Windows 365 license. The API is supported for both Windows 365 Enterprise and Windows 365 Business, ensuring broad applicability across deployment models.In this article, we will explore how to automate process of listing the Windows 365 Cloud PCs in a Tenant using Microsoft Graph API.

With Microsoft Graph, administrators can provision and manage Cloud PCs across their organization. When combined with the Intune API, Cloud PCs can be managed seamlessly alongside physical endpoints, providing a unified approach to device management.

Patch My PC

Windows 365 is your Personal Computer in the Cloud

In today’s dynamic work environment, organizations require robust solutions that strengthen resilience while maximizing return on investment. As IT environments continue to grow, many businesses are turning to cloud-based platforms such as Windows 365 to enhance security, streamline management, and ensure seamless connectivity.

The study identified several key benefits driving this impact. Enhanced productivity was a major outcome, with employees and contractors saving couple of minutes per day due to reduced outages and improved latency compared to traditional environments.

Cost savings were also significant, particularly through the implementation of a bring-your-own-PC program. By avoiding the purchase, provisioning, and maintenance of physical laptops, organizations were projected to save between $1.1 million and $1.2 million over three years.

How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-01
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-01

Beyond productivity and lifecycle savings, organizations realized further efficiencies by reducing IT infrastructure costs. Migrating to Windows 365 and Azure Virtual Desktop lowered expenses tied to on-premises operations, with projected savings ranging from $722,000 to $1.5 million over three years.

By leveraging Microsoft-managed services, organizations reduced reliance on extensive on-premises security infrastructure and personnel, resulting in projected savings of $60,000 to $122,000 over three years.

Know More about Permissions

Access to resources in Microsoft Graph is governed by permissions. As a developer, you must explicitly request and configure the appropriate permissions to interact with Windows 365 resources. Always choose the least-privileged permission(s) for this API. Use elevated permissions only when necessary for your app’s functionality.

Permission typeLeast privileged permissionsHigher privileged permissions
Delegated (work or school account)CloudPC.Read.AllCloudPC.ReadWrite.All
Delegated (personal Microsoft account)Not supported.Not supported.
ApplicationCloudPC.Read.AllCloudPC.ReadWrite.All
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Table-01

For additional details on these permissions, please refer to the table above. Microsoft has provided a comprehensive overview, and in most cases, the CloudPC.Read.All permission is sufficient to run this automation. Thanks to Microsoft for the table.

How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-02
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-02

Also, your Your tenant must have active Windows 365 licenses assigned to users for API operations to succeed. These permissions enable access to endpoints for listing Cloud PCs, managing lifecycle actions (reboot, resize, rename), and configuring provisioning policies.

How to List all Windows 365 Cloud PCs using Microsoft Graph API

Let’s learn how to List all Windows 365 Cloud PCs using Microsoft Graph API. Before proceeding, make sure you have required licenses to call the endpoints.

  • Sign in to the Graph Explorer with your credentials.
  • Click on Run query after typing the URL below. You should use the GET API request method.
https://graph.microsoft.com/v1.0/deviceManagement/virtualEndpoint/cloudPCs
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-03
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-03

When you click on Run query, you will receive a success message with the text ‘OK -200.’ The Response preview box will show the desired output.

How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-04
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-04

Customize the Response with OData Query Parameters

Well, the response above may not be sufficient for real-time automation. In practice, you often need to customize the output to retrieve only the parameters that are relevant to your scenario. Let me demonstrate how you can optimize Microsoft Graph API responses by precisely controlling the data that is returned.

Instead of retrieving all available properties and data, I will query only properties like displayName, imageDisplayName, userPrincipalName, managedDeviceName etc. You can select any properties that you would to display in the response.

https://graph.microsoft.com/v1.0/deviceManagement/virtualEndpoint/cloudPCs?$select=displayName,imageDisplayName,managedDeviceName,userPrincipalName
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-05
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-05

PowerShell Script to List all Windows 365 Cloud PCs

The below Powershell script will help you to list all Windows 365 Cloud PCs. This automation requires Microsoft Graph PowerShell modules. The SDK includes two modules, Microsoft. Graph and Microsoft.Graph.Beta, are respectively called the Microsoft Graph REST API v1.0 and Microsoft Graph REST API beta.

Read more : Best Guide to Install Microsoft Graph PowerShell Modules
# Get Cloud PC Data from Microsoft Graph API

# Install Graph module if needed
if (!(Get-Module -ListAvailable Microsoft.Graph.Authentication)) 

{
    Install-Module Microsoft.Graph.Authentication -Force -Scope CurrentUser
}

# Connect to Graph
Connect-MgGraph -Scopes "CloudPC.Read.All"
Write-Host "Connected to Graph successfully"

# Get Cloud PC data
$uri = "https://graph.microsoft.com/v1.0/deviceManagement/virtualEndpoint/cloudPCs?`$select=displayName,imageDisplayName,managedDeviceName,userPrincipalName"

$cloudPCs = Invoke-MgGraphRequest -Uri $uri -Method GET
Write-Host "Found $($cloudPCs.value.Count) Cloud PCs" -ForegroundColor Green

# Display results as table

 if ($cloudPCs.value.Count -gt 0) 
{
    $table = @()
    foreach ($pc in $cloudPCs.value)
     {
        $table += [PSCustomObject]@{
            ManagedDeviceName  = $pc.managedDeviceName
            DisplayName        = $pc.displayName
            ImageDisplayName   = $pc.imageDisplayName
            UserPrincipalName  = $pc.userPrincipalName
        }
    }

    $output = $table | Format-Table -AutoSize

    $output 
} 

else 

{
    Write-Host "No Cloud PCs found." -ForegroundColor Yellow
}



# Disconnect
Disconnect-MgGraph

End Result

To view the final result of the automation, copy and paste the PowerShell code into either PowerShell ISE or Visual Studio Code, then execute the script. Make sure to run it with administrator privileges.

How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API 1
How to List all Windows 365 Cloud PCs in your Tenant using Microsoft Graph API. Fig-06
Download the Script : Get-CloudPCData.ps1

Need Further Assistance or Have Technical Questions?

Join the LinkedIn Page and Telegram group to get the latest step-by-step guides and news updates. Join our Meetup Page to participate in User group meetings. Also, Join the WhatsApp Community to get the latest news on Microsoft Technologies. We are there on Reddit as well.

Author

About the Author: Sujin Nelladath, Microsoft Graph MVP with over 11 years of experience in SCCM device management and Automation solutions, writes and shares his experiences with Microsoft device management technologies, Azure, DevOps and PowerShell automation

Leave a Comment