Windows 365 Enterprise
A Microsoft cloud operating system.
365 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello, I've been trying to create a PowerShell script to end grace period of Cloud PCs but getting an error like below. Could you please help finding what's wrong?
Failed to stop grace period for Cloud PC ID <ID>: One or more errors occurred.
# Set execution policy to bypass (if needed)
Set-ExecutionPolicy Bypass -Scope Process -Force
# Import required modules
Import-Module Microsoft.Graph.Authentication
# Connect to Microsoft Graph with appropriate permissions
Connect-MgGraph -Scopes "CloudPC.ReadWrite.All"
# Retrieve all managed Cloud PCs and filter for those in grace period
$cloudPCs = Get-MgBetaDeviceManagementVirtualEndpointCloudPc -All | Where-Object { $_.status -eq 'inGracePeriod' }
#Get-MgBetaDeviceManagementVirtualEndpointCloudPc -All | Where-Object { $_.status -eq 'inGracePeriod' }|GM
foreach ($cloudPC in $cloudPCs)
{
$cloudPC | Select-Object ID, ManagedDeviceName, DisplayName, ProvisioningPolicyName, Status, GracePeriodEndDateTime | Format-Table -AutoSize
$cloudPCID = $cloudPC.ID
Write-Host "Ending GracePeriod of $($cloudPC.ID)"
try {
Stop-MgDeviceManagementVirtualEndpointCloudPcGracePeriod -CloudPcID $cloudPCID -WhatIf
}
catch {
Write-Host "Failed to stop grace period for Cloud PC ID $($cloudPCID): $_"
}
}