Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add Users from an OU to VBO365
## variables to set
$ad = ""
$cred = Get-Credential -UserName "administrator" -Message "AD"
$ouname = "My OU"
$orgname = ""
$reponame = "Default Backup Repository"
function New-VBOOUJob {
if ($(Get-Module -Name activedirectory) -eq $null) {
Import-Module activedirectory
write-verbose "Loading Active Directory"
if ($(Get-Module -Name Veeam.Archiver.PowerShell) -eq $null) {
$installpath = Get-ItemPropertyValue -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Veeam.Archiver.Service' -Name ImagePath -ErrorAction SilentlyContinue
if ($installpath -ne $null) {
$modulepath = Join-Path -Path (split-Path -Parent ($installpath -replace '"', "")) -ChildPath "Veeam.Archiver.PowerShell"
write-verbose "Loading VBO module from : $modulepath"
Import-module $modulepath
$ou = Get-ADOrganizationalUnit -Server $ad -Credential $cred -Filter { name -eq $ouname }
$users = Get-ADUser -Server $ad -Credential $cred -LDAPFilter "(name=*)" -SearchBase $ou.DistinguishedName -SearchScope OneLevel
$emaillist = $users | % { ("{0}@x.local" -f $_.SamAccountName) }
Write-Verbose "User list:"
write-verbose "$emaillist"
$org = Get-VBOOrganization -Name $orgname
$rep = Get-VBORepository -Name $reponame
$nam = $ou.DistinguishedName
$mbx = $org | Get-VBOOrganizationMailbox | ? { $ -in $emaillist }
$job = get-vbojob -name $nam
$result = $null
if ($job -eq $null) {
Write-Verbose "Making new job $nam"
$sch = New-VBOJobSchedulePolicy -PeriodicallyEvery Hours1 -Type Periodically
$result = Add-VBOJob -Organization $org -Name $nam -Repository $rep -SelectedMailboxes $mbx -SchedulePolicy $sch
} else {
Write-Verbose "Updating job $nam"
$result = Set-VBOJob -Job $job -SelectedMailboxes $mbx
if ($result -ne $null) {
write-verbose "Done"
New-VBOOUJob -ad $ad -cred $cred -ouname $ouname -reponame $reponame -orgname $orgname -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment