Public/Remove-DeletedUsers.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function Remove-DeletedUsers
{
    <#
    .SYNOPSIS
    Permanently removes deleted MSOL users.
     
    .DESCRIPTION
    Permanently removes accounts using the -Force switch.
     
    .EXAMPLE
    Remove-DeletedUsers
    #>

    [CmdletBinding()]
    Param()

    try 
    {
        Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force
    }
    catch 
    {
        throw "Error running script" 
    }

}