Maintain control of your Microsoft 365 data
Natalia Lupacheva
Veteran
Posts: 1143
Liked: 302 times
Joined: Apr 27, 2020 12:46 pm
Full Name: Natalia Lupacheva
Contact:

Re: Adding mulitple users to jobs through powershell

Post by Natalia Lupacheva »

Hi Morten,

please take a loot at the posts in this thread, hope this would help you to modify your script.

Thanks!
nielsengelen
Product Manager
Posts: 5797
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Adding mulitple users to jobs through powershell

Post by nielsengelen » 1 person likes this post

Morten, you are mixing 2 modules and this results in this as an error. I will check if I can come up with an adjusted working example.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
steveschaub
Lurker
Posts: 1
Liked: never
Joined: Mar 31, 2020 12:25 pm
Full Name: steve schaub
Contact:

[MERGED] Powershell to create O365 groups daily

Post by steveschaub »

On version 4.0.1.545
We are using MFA exclusively, so dynamic groups are unavailable for us to use in VBO jobs. I'm trying to create a Powershell script that will accomplish the same thing. Basically I want a set of groups used only by VBO, where each group has all users whose userid starts with a letter of the alphabet. Then I can use those groups to populate my VBO jobs and know that user adds/removals will get picked up during nightly backups. This powershell script would run daily and delete each group, then recreate them populated with the latest information.
Not wanting to recreate the wheel, I thought I'd start here and see if someone already such a script, or one that is close enough to give me a jump start.
thanks.
Polina
Veeam Software
Posts: 3195
Liked: 774 times
Joined: Oct 21, 2011 11:22 am
Full Name: Polina Vasileva
Contact:

Re: Adding mulitple users to jobs through powershell

Post by Polina »

Hi Steve and welcome to Veeam Forums!

In this thread, we're discussing the similar topic, so please take a look at the posts above.

Thanks!
Stibo
Influencer
Posts: 16
Liked: 4 times
Joined: Oct 30, 2019 9:53 am
Contact:

Re: Adding mulitple users to jobs through powershell

Post by Stibo »

ajtardio wrote: Feb 26, 2020 8:00 pm Not sure if this because Veeam has updated the Powershell scripting language, but had to do some tweaking to get this work. For me, I typically setup a job in the UI - then as the month goes on I want to add batches of users. Here is what I ended up using to add a list of users to a current job:

Some details to edit:
$repository - "Office 365 - 1 Year" (Name of your repo)
$name - "2020-02 Users" (Name of your job)
$Usernames - C:\Scripts\Users.txt (This should be a list of just the userPrincipalName of your user accounts to backup - no heading needed)

Code: Select all

$org=Get-VBOOrganization 
$repository = Get-VBORepository | where name -eq "Office 365 - 1 Year"
$name = Get-VBOJob -Name "2020-02 Users"
$Usernames = Get-Content -Path C:\Scripts\Users.txt
$orgusers = Get-VBOOrganizationUser -Organization $org
$users = compare $Usernames $orgusers.username -IncludeEqual | where sideindicator -eq "==" | select -ExpandProperty InputObject
$i=0
$foo = @()
ForEach($User in $Users)
{
	$newbackupuser = $orgusers | where {$_.username -like $user}
	$bi=New-VBOBackupItem -User $newbackupuser -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
	$foo += $bi 
	$i++
}

Set-VBOJob -Job $name -Repository $repository -SelectedItems $foo 
Hey ajtardio ,

Thanks for posting the script, but I have the same problem as swfguy, the script removed all entries from the current job and only added the one in the txt file.
Any idea how I could change this, meaning add the user(s) from the file but leave the entries in the jobs?

Thanks in advance!
habibalby
Veteran
Posts: 392
Liked: 33 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Adding mulitple users to jobs through powershell

Post by habibalby »

Hello,
Try this script; I've just modified it to allow me adding Teams to an existing job; Make sure you have a txt/csv file with header "Team"

Code: Select all

$Org = Get-VBOOrganization -Name "XXCXCC.onmicrosoft.com"
$Job = Get-VBOJob -Name "BAH MS Teams"
Import-Csv -Path C:\Scripts\Teams.txt | ForEach-Object{
$Tm = Get-VBOOrganizationTeam -Organization $Org -DisplayName $_.'Team' 
$newSite = New-VBOBackupItem -Team  $Tm
 Add-VBOBackupItem -Job $Job -BackupItem $newSite
} 
It will tell you cannot bind arugument 'Team', but at the same time while the script is looping through each line, you can run another PS console to run;

Code: Select all

$Job = Get-VBOJob -Name "BAH MS Teams"
(Get-VBOBackupItem -Job $Job).Count
Hope it helps.

Thanks,
Hussain
habibalby
Veteran
Posts: 392
Liked: 33 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Adding mulitple users to jobs through powershell

Post by habibalby » 1 person likes this post

Hello,
You can use this script to add SharePoint Sites into existing Job;

Code: Select all

$Org = Get-VBOOrganization -Name "cxcxcxc.onmicrosoft.com"
$Job = Get-VBOJob -Name "Test"
Import-Csv -Path C:\Scripts\SitesURL.txt | ForEach-Object{
$st = Get-VBOOrganizationSite -Organization $Org -Url $_.'Site' 
$newSite = New-VBOBackupItem -site  $st
Add-VBOBackupItem -Job $Job -BackupItem $newSite
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests