Set-MgUserLicense — Export Results — Stop on errorIT technician command center
Microsoft Graph · Entra ID and Graph

Set-MgUserLicense — Export Results — Stop on error

Use terminating error handling for Graph automation. Base task: Export the output of Set-MgUserLicense for documentation or review.

Copy-ready commandSet-MgUserLicense — Export Results — Stop on error
try { Set-MgUserLicense -UserId user@contoso.com -AddLicenses @{SkuId=$skuId} -RemoveLicenses @() | Export-Csv .\output.csv -NoTypeInformation -ErrorAction Stop } catch { Write-Error $_.Exception.Message }
Production warning

Directory write operations can affect tenant access.

Requirements and permissions

Requirements
Microsoft.Graph PowerShell SDK
Permissions
Graph delegated or application permissions
Last reviewed
2026-08-01

Examples

Stop on error

Use terminating error handling for Graph automation.

try { Set-MgUserLicense -UserId user@contoso.com -AddLicenses @{SkuId=$skuId} -RemoveLicenses @() | Export-Csv .\output.csv -NoTypeInformation -ErrorAction Stop } catch { Write-Error $_.Exception.Message }

Common errors

Command or option not supported

Confirm the installed platform version supports the base command and the added output or wrapper option.

Access denied or insufficient privileges

Run with the administrative role or delegated permission required by the underlying command.