set-vbrjobobject add VC folders

PowerShell script exchange

set-vbrjobobject add VC folders

Veeam Logoby EdwardPoll » Mon Feb 14, 2011 12:32 pm

Hello..

Powershell question for you..

We are trying to create jobs and add VMs based on VC Folder we can get it to add individual machines and resource groups (only if they have unique names) – but we can’t get it to add folders, or at least we aren’t getting the syntax right to add them if it’s possible. It’s what we put in the variable $vbrobjects in the scripts below;

$vbrjobname = "Test"
$vbrjob = Get-VBRJob | Where {$_.Name -eq $vbrjobname}
$vbrserverVC = Get-VBRServer | Where {$_.Type -eq "VC"}
$vbrobjects = ANY IDEAS WHAT WE PUT HERE TO DEFINE THE FOLDER WE WANT TO USE??

finally running this
Add-VBRJobObject -Job $vbrjob -Server $vbrserverVC -Object $vbrobjects

We can add VMs based on folder quite happily from the GUI, but it'd take days to go through the whole environment by hand like that.

Any help would be much appreciated..

Cheers

Ed
EdwardPoll
Influencer
 
Posts: 17
Liked: never
Joined: Wed Feb 09, 2011 9:03 am
Full Name: Edward Poll

Re: set-vbrjobobject add VC folders

Veeam Logoby Vitaliy S. » Mon Feb 14, 2011 1:53 pm

Edward,

The syntax for $vbrserverVC should look like this:

Code: Select all
$vbrserverVC = Get-VBRServer | where {$_.Name -eq "VC_Name"} | Find-VBRObject | Where {$_.Name -eq "VM_Name"}

Unfortunately, you cannot return any folder name while executing $vbrobjects, so to workaround this limitation, please follow the instuctions below:

For each object that has been returned by Find-VBRObject, execute FindParent cmdlet, this would allow you to find VMs in particular folder and then add those VMs to the backup job.

Code: Select all
Get-VBRServer | where {$_.Name -eq "VC_Name"} | Find-VBRObject | where {$_.FindParent("Folder").Name -eq "VM_Name"}

Hope it helps!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: set-vbrjobobject add VC folders

Veeam Logoby jkcouch » Thu Jul 07, 2011 3:31 am

Vitaliy S. wrote:Edward,

The syntax for $vbrserverVC should look like this:

Code: Select all
$vbrserverVC = Get-VBRServer | where {$_.Name -eq "VC_Name"} | Find-VBRObject | Where {$_.Name -eq "VM_Name"}

Unfortunately, you cannot return any folder name while executing $vbrobjects, so to workaround this limitation, please follow the instuctions below:

For each object that has been returned by Find-VBRObject, execute FindParent cmdlet, this would allow you to find VMs in particular folder and then add those VMs to the backup job.

Code: Select all
Get-VBRServer | where {$_.Name -eq "VC_Name"} | Find-VBRObject | where {$_.FindParent("Folder").Name -eq "VM_Name"}

Hope it helps!



Thanks for this. Is this still a limitation? Is there any other known workaround to assign folder objects rather than VMs from a known folder?
jkcouch
Enthusiast
 
Posts: 30
Liked: never
Joined: Sun Jun 26, 2011 7:02 pm
Full Name: Jeff Couch

Re: set-vbrjobobject add VC folders

Veeam Logoby Vitaliy S. » Thu Jul 07, 2011 9:01 am

No other workarounds for now, you should be using the instructions above. Thanks!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: set-vbrjobobject add VC folders

Veeam Logoby Sethbartlett » Mon Jul 25, 2011 6:21 pm

There actually is a way to add a folder into a job through powershell, but it is a little rough. Here is the following code:
Code: Select all
$Server = Get-VBRServer | ?{$_.name -eq "MyVC"}
$Job = Get-VBRJob | ?{$_.name -eq "MyJob"}
$FaV = ((New-Object -typename Veeam.Backup.Core.InfrastructureTree.HostsAndClustersLoader).LoadHierarchy($Server.Info)).FoldersAndVms()
$Entity = $FaV.GetChild((Find-VBRObject $Server | ?{$_.name -eq "MyVMName"})[0].VmFolder, 4, $true)

Add-VBRJobObject -Job $Job -Server $Server -Entities $Entity



For the following line, you just need to make sure you look up a VM that is in the folder you are wanting to add(You only need to do this once)

Code: Select all
$Entity = $FaV.GetChild((Find-VBRObject $Server | ?{$_.name -eq "MyVMName"})[0].VmFolder, 4, $true)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Powershell

Veeam Logoby BarryCoombs » Wed Aug 10, 2011 1:40 pm

[merged]

Has someone got a simple example of creating a Veeam job using powershell, I need to create the backups of VM Folders.

I imagine this should be an easy task but dont really seem to be getting very far.
BarryCoombs
Enthusiast
 
Posts: 30
Liked: never
Joined: Fri May 22, 2009 2:46 pm

Re: set-vbrjobobject add VC folders

Veeam Logoby BarryCoombs » Wed Aug 10, 2011 1:57 pm

Can someone just put this together into one script, I have tried merging the bits in this thread but am just getting errors. Can't beleive there isnt an example of how to do somehting as simple as this in the userguide
BarryCoombs
Enthusiast
 
Posts: 30
Liked: never
Joined: Fri May 22, 2009 2:46 pm

Re: set-vbrjobobject add VC folders

Veeam Logoby BarryCoombs » Wed Aug 10, 2011 2:07 pm

Sethbartlett wrote:There actually is a way to add a folder into a job through powershell, but it is a little rough. Here is the following code:
Code: Select all
$Server = Get-VBRServer | ?{$_.name -eq "MyVC"}
$Job = Get-VBRJob | ?{$_.name -eq "MyJob"}
$FaV = ((New-Object -typename Veeam.Backup.Core.InfrastructureTree.HostsAndClustersLoader).LoadHierarchy($Server.Info)).FoldersAndVms()
$Entity = $FaV.GetChild((Find-VBRObject $Server | ?{$_.name -eq "MyVMName"})[0].VmFolder, 4, $true)

Add-VBRJobObject -Job $Job -Server $Server -Entities $Entity



For the following line, you just need to make sure you look up a VM that is in the folder you are wanting to add(You only need to do this once)

Code: Select all
$Entity = $FaV.GetChild((Find-VBRObject $Server | ?{$_.name -eq "MyVMName"})[0].VmFolder, 4, $true)


When running this I get Parameter Job is null
BarryCoombs
Enthusiast
 
Posts: 30
Liked: never
Joined: Fri May 22, 2009 2:46 pm

Re: set-vbrjobobject add VC folders

Veeam Logoby Gostev » Wed Aug 10, 2011 2:08 pm

Barry, reading through the discussion above, there is no supported way to add folder to the job through PowerShell today. The workaround requires interacting with internal VBR data structures, which is unsupported.

Regarding missing examples, everyone wants something different - we cannot have all possible examples in the User Guide... it is already 200 pages long. This is why we have forums, so that everyone can share their own scripts they use. If you search this forum for PowerShell, you will find tons of those.

Thanks.
Gostev
Veeam Software
 
Posts: 21390
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: set-vbrjobobject add VC folders

Veeam Logoby BarryCoombs » Wed Aug 10, 2011 2:14 pm

Thanks Gostev, as far as I can see there is no example of creating a backup using powershell in your manual, using folders or not, I would suggest the use of powershell in you product would be primarily to create backup jobs? Even the powershell help is poor tbh. Looks like I will need to create 60+ jobs manually
BarryCoombs
Enthusiast
 
Posts: 30
Liked: never
Joined: Fri May 22, 2009 2:46 pm

Re: set-vbrjobobject add VC folders

Veeam Logoby Gostev » Wed Aug 10, 2011 2:25 pm

Well, there is example of editing job settings in the User Guide, showing how to set job settings, so no big difference from creating the job. But, since you need to stuff your jobs with VM folders, you would have to perform this operation manually anyway, unfortunately.
Gostev
Veeam Software
 
Posts: 21390
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: set-vbrjobobject add VC folders

Veeam Logoby tsightler » Wed Jul 18, 2012 1:24 am

As a small improvement to the unsupported code above, there's no real reason that you have to use a VM to look up a parent folder. If you know the name of the folder then something like this should would fine:

Code: Select all
$Server = Get-VBRServer -Name "<Your_vCenter_Server>"
$Job = Get-VBRJob -Name "<Job_to_Edit>"
$Folder = "<Folder_to_Add_to_Job>"

# Populate the top of the Folders and VMs Object View
$FaV = ((New-Object -typename Veeam.Backup.Core.InfrastructureTree.HostsAndClustersLoader).LoadHierarchy($Server.Info)).FoldersAndVms()

# Find the Folder Object for the Folder being added
$FolderObj = Find-VBRViEntity -Server $Server -VMsAndTemplates -Name $Folder

#Call GetChild with proper parameters to create the folder entity object
$Entity = $FaV.GetChild($FolderObj.Reference, "Folder", $true)

#Add object to job
Add-VBRJobObject -Job $Job -Server $Server -Entities $Entity


Even though the above code is "unsupported" it's pretty safe in that the only thing really not supported is the call to build the $FaV view. The default view populated by "Find-VBRObjects" is the "Host and Clusters" view which doesn't include the folder hierarchy thus calls to the "GetChild" method with the "Folder" parameter don't return useful info.

I tried to comment the code so that it makes more sense. Please feel free to ask questions if anything is not clear.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: set-vbrjobobject add VC folders

Veeam Logoby tsightler » Wed Jul 18, 2012 1:38 am

Vitaliy S. wrote:
Code: Select all
Get-VBRServer | where {$_.Name -eq "VC_Name"} | Find-VBRObject | where {$_.FindParent("Folder").Name -eq "VM_Name"}


BTW, this method doesn't appear to work, at least with 6.x, because the "FindParent("Folder") command returns the "Host" folder, not the vCenter folder. That's why the "unsupported" workaround that builds the VM and Folders view is required. It would be nice if Find-VBRObject was enhanced with a parameter to allow you to return the various views available in the GUI instead of always returning the Hosts and Clusters view.

If there is a way to make this work I'd sure like to know it.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: set-vbrjobobject add VC folders

Veeam Logoby Sethbartlett » Wed Jul 18, 2012 2:21 am

There isn't and that was part of the problem. What's really crazy about it, is that FInd-VBRViEntity has -VMsAndTemplates, DatastoresAndHosts and a slew of other things to search for, but for some reason, FoldersAndVms isn't in that list.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: set-vbrjobobject add VC folders

Veeam Logoby tsightler » Wed Jul 18, 2012 3:03 am

Actually, -VMsAndTemplates is the correct view, and does have the object, but it returns a type of CViFolderItem, which is fine, and is perfectly usable for Add-VBRViJob, but doesn't work with Add-VBRJobObject because, while both use an option called "-Entity", they are two completely different data types. So another simple fix is to update Add-VBRJobObject, or perhaps create Add-VBRViJobObject that uses the same parameters as Add-VBRViJob.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Next

Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests