forked from nielsengelen/veeam-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVBO365-DeleteRemovedUsersFromJob.ps1
39 lines (32 loc) · 1.46 KB
/
VBO365-DeleteRemovedUsersFromJob.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.NAME
Veeam Backup for Microsoft Office 365 clean up script for O365 accounts without an Exchange account
.SYNOPSIS
Remove users without Exchange account from backup jobs
.DESCRIPTION
Script to use for removing O365 accounts without an Exchange account from backup jobs
Released under the MIT license.
.LINK
http://www.github.com/nielsengelen
#>
Import-Module "C:\Program Files\Veeam\Backup365\Veeam.Archiver.PowerShell\Veeam.Archiver.PowerShell.psd1"
$JobName = "TEST"
$Job = Get-VBOJob -Name $JobName
$JobSession = Get-VBOJobSession -Job $Job -Last
$SelectedItems = $Job.SelectedItems
$SelectedUser = $Job.SelectedItems.User
$JobLog = $JobSession.Log
$Seperator = '\[Warning\].*(Exchange\saccount\swas\snot\sfound)'
$Warnings = $JobLog.Title -match "$Seperator"
foreach ($JobWarning in $Warnings) {
$UID = $JobWarning.Split('(ID: ')
$UID = $UID[-1].TrimEnd(')')
$RemoveUser = $SelectedItems | Where-Object {$_.User.OfficeId -eq $UID}
$DisplayName = $($SelectedUser | Where-Object {$_.OfficeId -eq $UID} | Select-Object -ExpandProperty DisplayName)
try {
Remove-VBOBackupItem -Job $job -BackupItem $RemoveUser -ErrorAction Stop
Write-Host -ForegroundColor Green "User named '$DisplayName' with GUID '$UID' has been removed from backup job '$($Job.Name)'."
} catch {
Write-Host -ForegroundColor Red "User named '$DisplayName' with GUID '$UID' could not be removed from backup job '$($Job.Name)'."
}
}