-
- Novice
- Posts: 5
- Liked: never
- Joined: Sep 26, 2017 6:03 pm
- Full Name: Omar Nova
- Contact:
Adding mulitple users to jobs through powershell
Working on creating new jobs and adding users to current jobs through powershell. I'm using the script below to add single users but would like to see if there is a way to add multiple users from a csv or txt file.
$org = Get-VBOOrganization -Name "xyz.onmicrosoft.com"
$user = Get-VBOOrganizationUser -Organization $org -Name "Username"
$backupItemUser = New-VBOBackupItem -User $user -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
$job = Get-VBOJob -Name "yourjobgoeshere"
Add-VBOBackupItem -Job $job -BackupItem $backupItemUser
$org = Get-VBOOrganization -Name "xyz.onmicrosoft.com"
$user = Get-VBOOrganizationUser -Organization $org -Name "Username"
$backupItemUser = New-VBOBackupItem -User $user -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
$job = Get-VBOJob -Name "yourjobgoeshere"
Add-VBOBackupItem -Job $job -BackupItem $backupItemUser
-
- 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
Hi Omar,
I reached out to our RnD team to get the answer, and here's their suggestion:
Where $bi stands for a backup items scope. Hope this helps.
Great question and thanks for asking!
I reached out to our RnD team to get the answer, and here's their suggestion:
Code: Select all
$org=Get-VBOOrganization
$usernames=Get-Content -Path C:\Folder\Your Users.txt
$Users=Get-VBOOrganizationUser -Organization $org | ?{$usernames.Contains($_.UserName)}
$bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
Add-VBOJob -Organization $org -Name Job1 -Repository (Get-VBORepository) -SelectedItems $bi
Great question and thanks for asking!
-
- Novice
- Posts: 5
- Liked: never
- Joined: Sep 26, 2017 6:03 pm
- Full Name: Omar Nova
- Contact:
Re: Adding mulitple users to jobs through powershell
Thanks, for the reply. I tried the code provided but i receive this error message. i'm adding the names on the list with last name, first name...not sure if that is causing the issue but this is how we look up the users when adding them through the gui.
New-VBOBackupItem : Cannot bind argument to parameter 'User' because it is null.
At line:4 char:29
+ $bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$tr ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [New-VBOBackupItem], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Veeam.Archiver.PowerShell.Cmdlets.BackupItems.NewVBO
BackupItem
Add-VBOJob : Cannot convert 'System.Object[]' to the type 'Veeam.Archiver.PowerShell.Model.VBORepository' required by parameter
'Repository'. Specified method is not supported.
At line:5 char:68
+ ... $org -Name "user mailboxes 2" -Repository (Get-VBORepository) -Select ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-VBOJob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOJob
New-VBOBackupItem : Cannot bind argument to parameter 'User' because it is null.
At line:4 char:29
+ $bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$tr ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [New-VBOBackupItem], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Veeam.Archiver.PowerShell.Cmdlets.BackupItems.NewVBO
BackupItem
Add-VBOJob : Cannot convert 'System.Object[]' to the type 'Veeam.Archiver.PowerShell.Model.VBORepository' required by parameter
'Repository'. Specified method is not supported.
At line:5 char:68
+ ... $org -Name "user mailboxes 2" -Repository (Get-VBORepository) -Select ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-VBOJob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOJob
-
- 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
Omar,
My apologies for the delayed response.
I just tried the provided script in my lab and it works fine. The names were listed in .txt in the following way:
username1@organization.onmicrosoft.com
username2@organization.onmicrosoft.com
username3@organization.onmicrosoft.com
My apologies for the delayed response.
I just tried the provided script in my lab and it works fine. The names were listed in .txt in the following way:
username1@organization.onmicrosoft.com
username2@organization.onmicrosoft.com
username3@organization.onmicrosoft.com
-
- Novice
- Posts: 5
- Liked: never
- Joined: Sep 26, 2017 6:03 pm
- Full Name: Omar Nova
- Contact:
Re: Adding mulitple users to jobs through powershell
Thanks for the Reply, after a few trial and errors here is what worked...for the usernames i also used the email address, not sure why in my environment it didn't work the way you recommended but we have something that works now and will facilitate creating our jobs more easier. Hope this helps others down the road.
$org=Get-VBOOrganization -Name "YourOrggoeshere"
$usernames=Get-Content -Path C:\migration\mailboxes.txt
$Users=Get-VBOOrganizationUser -Organization $org | ?{$usernames.Contains($_.UserName)}
$job=get-vbojob -name "Jobnamegoeshere"
$bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
Add-vbobackupitem -job $job -backupitem $bi
$org=Get-VBOOrganization -Name "YourOrggoeshere"
$usernames=Get-Content -Path C:\migration\mailboxes.txt
$Users=Get-VBOOrganizationUser -Organization $org | ?{$usernames.Contains($_.UserName)}
$job=get-vbojob -name "Jobnamegoeshere"
$bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
Add-vbobackupitem -job $job -backupitem $bi
-
- Veteran
- Posts: 392
- Liked: 33 times
- Joined: Jul 18, 2011 9:30 am
- Full Name: Hussain Al Sayed
- Location: Bahrain
- Contact:
[MERGED] PowerShell: Add-VBOJob & New-VBOBackupItem from CSV File
Hi Guys,
I'm trying to achieve the following;
1.List all users in a CSV file.
2.Create a Backup Job and import the selected users from a csv;
But i'm always getting error message;
New-VBOBackupItem : Cannot bind parameter 'User'. Cannot convert the "username"...
Any help.. ?
Regards,
I'm trying to achieve the following;
1.List all users in a CSV file.
2.Create a Backup Job and import the selected users from a csv;
Code: Select all
$org=Get-VBOOrganization
$Usernames = import-csv -path C:\Scripts\UserList.csv
ForEach($User in $Usernames)
{
$User.Mailbox
Get-VBOOrganizationUser -Name $User.Mailbox -Organization $Org
$bi=New-VBOBackupItem -User $User.Mailbox -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
Add-VBOJob -Organization $org -Name Job99 -Repository (Get-VBORepository) -SelectedItems $bi
}
New-VBOBackupItem : Cannot bind parameter 'User'. Cannot convert the "username"...
Any help.. ?
Regards,
-
- Veeam Software
- Posts: 3195
- Liked: 774 times
- Joined: Oct 21, 2011 11:22 am
- Full Name: Polina Vasileva
- Contact:
Re: PowerShell: Add-VBOJob & New-VBOBackupItem from CSV File
Hi Hussain,
Kindly review the above posts in this thread to get some hints on how to fix your script. Hope they will help you.
Thanks!
Kindly review the above posts in this thread to get some hints on how to fix your script. Hope they will help you.
Thanks!
-
- 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
Hi Polina,
Thanks for your reference, but this script it doesn;t exit out of the Foreach loop at all.. Unless I kill the entire console and Application.. The .txt file should contains an header "UserName" isn't ?
Regards,
Thanks for your reference, but this script it doesn;t exit out of the Foreach loop at all.. Unless I kill the entire console and Application.. The .txt file should contains an header "UserName" isn't ?
Regards,
-
- 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
Hi there,
this won't work;
The CSV file contains header Username and the username format is username@domain.com;
Any help...?
Regards,
this won't work;
Code: Select all
$Org = Get-VBOOrganization
$Usernames = Import-csv -Path "C:\Scripts\UserList.csv"
$Users=Get-VBOOrganizationUser -Organization $org | ?{$usernames.Contains($_.UserName)}
$bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$false -Sites:$false
Add-VBOJob -Organization $org -Name JobBmA -Repository (Get-VBORepository) -SelectedItems $bi
Any help...?
Regards,
-
- 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
Hi Hussain,
Try using "Get-Content -Path "C:\Scripts\UserList.csv" instead of "Import-csv" in the above script, and kill a header in your csv leaving just usernames in the username@domain.com format.
Btw, in your initial script, one of the ussies was that it tried to create a job with the same "Job99" name for each of your users, which couldn't work. If you added an index parameter "$i=0" and correspondingly changed job name to "-Name "Job$i", a separate job would be created for each user.
Try using "Get-Content -Path "C:\Scripts\UserList.csv" instead of "Import-csv" in the above script, and kill a header in your csv leaving just usernames in the username@domain.com format.
Btw, in your initial script, one of the ussies was that it tried to create a job with the same "Job99" name for each of your users, which couldn't work. If you added an index parameter "$i=0" and correspondingly changed job name to "-Name "Job$i", a separate job would be created for each user.
-
- 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
Hi Poline,
I've tried that and still didn't work. Any help..?
Regards,
I've tried that and still didn't work. Any help..?
Regards,
-
- 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
Hussain,
Which error(s) did you get?
Which error(s) did you get?
-
- 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
Hi Polina,
Here's the error;
Here's the error;
Code: Select all
PS C:\Scripts> .\Add-VBROJob-Mailbox.ps1
Get-VBOOrganizationUser : Connecting to remote server outlook.office365.com failed with the following error message :
Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At C:\Scripts\Add-VBROJob-Mailbox.ps1:51 char:10
+ $users = Get-VBOOrganizationUser -Name $usernames -Organization $Org
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- 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
Hi Polina,
Here;s the original error, the ignore the above error as it indicates to username/password error accessing the Tenant Organization.
Here;s the original error, the ignore the above error as it indicates to username/password error accessing the Tenant Organization.
Code: Select all
PS C:\Scripts> .\Add-VBROJob-Mailbox.ps1
New-VBOBackupItem : Cannot bind parameter 'User'. Cannot convert the "jdagami@domain.com " value of type "System.String"
to type "Veeam.Archiver.PowerShell.Model.VBOOrganizationUser".
At C:\Scripts\Add-VBROJob-Mailbox.ps1:27 char:29
+ $bi=New-VBOBackupItem -User $User -Mailbox:$True -ArchiveMailbox:$true -OneDrive ...
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-VBOBackupItem], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Archiver.PowerShell.Cmdlets.BackupItems.NewVBOBacku
pItem
Add-VBOJob : Cannot validate argument on parameter 'SelectedItems'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\Scripts\Add-VBROJob-Mailbox.ps1:28 char:90
+ ... -SelectedItems $bi
+ ~~~
+ CategoryInfo : InvalidData: (:) [Add-VBOJob], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOJob
New-VBOBackupItem : Cannot bind argument to parameter 'User' because it is null.
At C:\Scripts\Add-VBROJob-Mailbox.ps1:54 char:29
+ $bi=New-VBOBackupItem -User $users -Mailbox:$True -ArchiveMailbox:$true -OneDriv ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [New-VBOBackupItem], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Veeam.Archiver.PowerShell.Cmdlets.BackupI
tems.NewVBOBackupItem
Add-VBOJob : Cannot validate argument on parameter 'SelectedItems'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\Scripts\Add-VBROJob-Mailbox.ps1:55 char:92
+ ... -SelectedItems $bi
+ ~~~
+ CategoryInfo : InvalidData: (:) [Add-VBOJob], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOJob
-
- 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
And the code i'm using is this;
Code: Select all
$org=Get-VBOOrganization
$usernames = Get-Content -Path C:\Scripts\Users.txt
ForEach($User in $Usernames)
{
Get-VBOOrganizationUser -Name $User -Organization $org
$bi=New-VBOBackupItem -User $User -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
Add-VBOJob -Organization $org -Name Job99 -Repository (Get-VBORepository) -SelectedItems $bi
}
-
- 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
So, let's fix the above script a bit and make it work:
1. The following line is missing: $Users=Get-VBOOrganizationUser -Organization $org| ?{$usernames.Contains($_.UserName)}
2. Need to add index parameter to set a unique name for each job (as with ForEach you'll get a separate backup job for each user)
3. Modify ForEach the following way: ForEach($User in $Users)
This way, you should get the following script:
Thanks!
1. The following line is missing: $Users=Get-VBOOrganizationUser -Organization $org| ?{$usernames.Contains($_.UserName)}
2. Need to add index parameter to set a unique name for each job (as with ForEach you'll get a separate backup job for each user)
3. Modify ForEach the following way: ForEach($User in $Users)
This way, you should get the following script:
Code: Select all
$org=Get-VBOOrganization
$usernames = Get-Content -Path C:\Scripts\Users.txt
$Users=Get-VBOOrganizationUser -Organization $org| ?{$usernames.Contains($_.UserName)}
$i=0
ForEach($User in $Users)
{
Get-VBOOrganizationUser -Name $User -Organization $org
$bi=New-VBOBackupItem -User $User -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
Add-VBOJob -Organization $org -Name Job99$i -Repository (Get-VBORepository) -SelectedItems $bi
$i++
}
Thanks!
-
- Influencer
- Posts: 18
- Liked: 5 times
- Joined: May 14, 2018 11:54 am
- Full Name: Markus Johansson
- Location: Gothenburg
- Contact:
Re: Adding mulitple users to jobs through powershell
I think it will would work better with the array ($foo)
Code: Select all
$org=Get-VBOOrganization
$usernames = Get-Content -Path C:\Scripts\Users.txt
$Users=Get-VBOOrganizationUser -Organization $org| ?{$usernames.Contains($_.UserName)}
$i=0
$foo = @()
ForEach($User in $Users)
{
Get-VBOOrganizationUser -Name $User -Organization $org
$bi=New-VBOBackupItem -User $User -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
$foo += $bi
$i++
}
Add-VBOJob -Organization $org -Name Job99$i -Repository (Get-VBORepository) -SelectedItems $foo
-
- 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
Hi Whimark,
Thank you very much, this has worked... but it looks like its a bit slow and doesn't exit the command unless I hit Enter to quit it.. At least it does the job. much appreciated your effort and taking the time to write it up..
Regards,
Thank you very much, this has worked... but it looks like its a bit slow and doesn't exit the command unless I hit Enter to quit it.. At least it does the job. much appreciated your effort and taking the time to write it up..
Regards,
-
- Influencer
- Posts: 18
- Liked: 5 times
- Joined: May 14, 2018 11:54 am
- Full Name: Markus Johansson
- Location: Gothenburg
- Contact:
Re: Adding mulitple users to jobs through powershell
Yes, the reason for that the script is so slow is beacuse "Get-VBOOrganizationUser -Name $User -Organization $org" I present in the foreach, which I didnt noticed when I added the array. If that where removed I think it would have run faster for you. Strange that you needed to hit enter to quit
-
- 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
Thank you very much.. I will try to present it within the ForEach and let's see if that will speed it up.
Regards,
Regards,
-
- 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
Hi Whimark,
I tried to remove the pipe line between the VBOOrganizationUser, but that didn't help.
@Veeam {PowerShell scripting should make our life easier rather than waiting hell of time to get one job to exist the PowerShell Console}
Regards,
I tried to remove the pipe line between the VBOOrganizationUser, but that didn't help.
@Veeam {PowerShell scripting should make our life easier rather than waiting hell of time to get one job to exist the PowerShell Console}
Regards,
-
- Influencer
- Posts: 18
- Liked: 5 times
- Joined: May 14, 2018 11:54 am
- Full Name: Markus Johansson
- Location: Gothenburg
- Contact:
Re: Adding mulitple users to jobs through powershell
Hi Habibalby,
Can you send me a version of your CSV file?
Can you send me a version of your CSV file?
-
- 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
hi Markus,
its simple .txt file that includes email only and same format as Get-VBOOrganizationUser;
OrganizationId : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OfficeId : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OnPremisesId : 00000000-0000-0000-0000-000000000000
DisplayName : xxxxxxxxxxxxxxx
UserName : xxxxxxxxxxxx (The txt file is populated with the same format..)
Type : User
IsBackedUp : True
its simple .txt file that includes email only and same format as Get-VBOOrganizationUser;
OrganizationId : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OfficeId : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OnPremisesId : 00000000-0000-0000-0000-000000000000
DisplayName : xxxxxxxxxxxxxxx
UserName : xxxxxxxxxxxx (The txt file is populated with the same format..)
Type : User
IsBackedUp : True
-
- Influencer
- Posts: 18
- Liked: 5 times
- Joined: May 14, 2018 11:54 am
- Full Name: Markus Johansson
- Location: Gothenburg
- Contact:
Re: Adding mulitple users to jobs through powershell
Hi Hussain
I think this should work for you. Just update the "job99" to the correct repository and job name.
If you want to add users to a current job remove the bracket in the foreach and and a bracket to add-vbojob (#Add-VBOJob -Organization $org -Name $name -Repository $repository -SelectedItems $foo)
I think this should work for you. Just update the "job99" to the correct repository and job name.
If you want to add users to a current job remove the bracket in the foreach and and a bracket to add-vbojob (#Add-VBOJob -Organization $org -Name $name -Repository $repository -SelectedItems $foo)
Code: Select all
$org=Get-VBOOrganization
$repository = Get-VBORepository | where name -eq "Job99"
$name = "Job99"
$Usernames = import-csv -path C:\Scripts\UserList.csv
$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 where {$_.username -like $user}
$bi=New-VBOBackupItem -User $newbackupuser -Mailbox:$True -ArchiveMailbox:$true -OneDrive:$true -Sites:$true
#Add-VBOBackupItem -Job $name -BackupItem $bi
$foo += $bi
$i++
}
Add-VBOJob -Organization $org -Name $name -Repository $repository -SelectedItems $foo
-
- 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
Markus,
Thank you for your input on the matter, much appreciated!
I'll use the updated script for my lab as well )
Thank you for your input on the matter, much appreciated!
I'll use the updated script for my lab as well )
-
- 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
HI Markus,
The updated script didn't work... I managed to create all the jobs with the previous script. Much appreciated your effort on making this a really and optimum solution.
Regards,
The updated script didn't work... I managed to create all the jobs with the previous script. Much appreciated your effort on making this a really and optimum solution.
Regards,
-
- Novice
- Posts: 3
- Liked: never
- Joined: Feb 26, 2020 7:46 pm
- Full Name: AJ Tardio
- Contact:
Re: Adding mulitple users to jobs through powershell
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)
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
@ajtardio
https://www.ajtardio.com
https://www.ajtardio.com
-
- Lurker
- Posts: 1
- Liked: never
- Joined: Mar 04, 2020 6:33 pm
- Full Name: Scott Faulkner
- Contact:
Re: Adding mulitple users to jobs through powershell
I used ajtardio's script (Feb 26 post) to attempt to add a single new user to an existing job. It did add the user, but removed all other existing user entries. I was able to populate the text file used in the script with all users that were supposed to be in that job and added them back. I have several jobs that I need to add a sizeable number of users to. I can accomplish what I need to do by adding new users to the existing text file used by the script, a rolling list so to speak. Is there an easy mod to this script so that it does a user-add only to an existing job?
-
- Novice
- Posts: 3
- Liked: never
- Joined: Feb 26, 2020 7:46 pm
- Full Name: AJ Tardio
- Contact:
Re: Adding mulitple users to jobs through powershell
Thanks for pointing that out @swfguy - I keep a running list of the users I have for the backup job so I just add them all when I run this script. It doesn't mess the job up at all, from what I've seen it runs a differential job for that user if it's already been backed up before.
@ajtardio
https://www.ajtardio.com
https://www.ajtardio.com
-
- Enthusiast
- Posts: 25
- Liked: 4 times
- Joined: Jun 04, 2020 6:55 pm
- Full Name: Morten Hemmingsen
- Contact:
[MERGED] Cannot bind parameter User - Powershell error
Hi.
I'm trying to run a powershell script where I look for all users in a group from azuread starting with "A". I'm able to do that with this command:
$OneDriveA = Get-AzureADGroupMember -All 1 -ObjectId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Where {$_.DisplayName -like "A*"}
I then try to use is in Niels' script like this, but I get this error: New-VBOBackupItem : Cannot bind parameter 'User'. Cannot convert the "class User
How do I bind by output in $OneDriveA with New-VBOBackupItem -User $User ?
Thanks
Morten
I'm trying to run a powershell script where I look for all users in a group from azuread starting with "A". I'm able to do that with this command:
$OneDriveA = Get-AzureADGroupMember -All 1 -ObjectId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Where {$_.DisplayName -like "A*"}
I then try to use is in Niels' script like this, but I get this error: New-VBOBackupItem : Cannot bind parameter 'User'. Cannot convert the "class User
How do I bind by output in $OneDriveA with New-VBOBackupItem -User $User ?
Code: Select all
# Modify the values below to your needs
$Organization ="×××"
$BackupJob = "Test"
# Do not change below unless you know what you are doing
Import-Module "C:\Program Files\Veeam\Backup365\Veeam.Archiver.PowerShell\Veeam.Archiver.PowerShell.psd1"
# Get the Organization
$Org = Get-VBOOrganization -Name $Organization
# Leverage the Job which backs up the required OneDrives
$Job = Get-VBOJob -Name $BackupJob
# Get OneDriveUsers
$OneDriveA = Get-AzureADGroupMember -All 1 -ObjectId 3e561af8-4b68-44cb-ace7-ac8cbb99205e | Select-Object -Property Type | Where {$_.DisplayName -like "A*"}
# Go through all the Users and add them to the job
ForEach ($User in $OneDriveA) {
$Item = New-VBOBackupItem -User $User -Mailbox:$False -ArchiveMailbox:$false -OneDrive:$true -Sites:$false
Add-VBOBackupItem -Job $Job -BackupItem $Item
}
Morten
Who is online
Users browsing this forum: No registered users and 9 guests