Remove-MgmtGraphUser
MgmtGraph: Deletes a Microsoft Graph user account
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Users
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$Identity
)
Process {
try {
$params = @{
'UserId' = $Identity
'Confirm' = $false
'ErrorAction' = 'Stop'
}
Remove-MgUser @params
$result = [PSCustomObject]@{
Identity = $Identity
Action = "UserDeleted"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}Specifies the UserPrincipalName or ID of the user to delete.