Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Users from an OU to VBO365
## variables to set
$ad = "mydomain.com"
$cred = Get-Credential -UserName "administrator" -Message "AD"
$ouname = "My OU"
$orgname = "exchange.mydomain.com"
$reponame = "Default Backup Repository"
##
function New-VBOOUJob {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)][string]$ad,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$cred,
[Parameter(Mandatory=$true)][string]$ouname,
[Parameter(Mandatory=$true)][string]$orgname,
[Parameter(Mandatory=$true)][string]$reponame
)
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 | ? { $_.email -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
You can’t perform that action at this time.