powershellgraphazure-active-directorymicrosoft-graph-apimicrosoft-graph-mail

How to return Deleted User using Microsoft Graph Module in PowerShell


I've been using this MSOL command to check if a user is in soft-delete stage but I'm just wondering how can I do the same with Graph Module?

MSOL

Get-MsolUser –ReturnDeletedUsers –SearchString $CSVOwner

Graph

Get-Mguser

I know I might need to use Get-Mguser cmdlets but not sure how can I return only the soft-deleted user. any help or suggestion would be really appreciated.


Solution

  • You need to use Get-MgDirectoryDeletedItemAsUser but this cmdlet is available in prerelease version 2.0.0-rc1.

    It requires to install Microsoft.Graph module with prerelease version.

    # check version of PowerShellGet module you need at least version 2.0
    # Install-Module PowerShellGet -Force -AllowClobber
    
    # install Microsoft.Graph module and include prerelease
    Install-Module Microsoft.Graph -AllowPrerelease -Force -AllowClobber
    
    # now you should be able to call Get-MgDirectoryDeletedItemAsUser
    Get-MgDirectoryDeletedItemAsUser
    

    Resources:

    Get deleted user in PS