PowerShell script exchange
Post Reply
dries.vergote
Service Provider
Posts: 40
Liked: 5 times
Joined: Apr 24, 2015 2:51 pm
Full Name: Dries Vergote
Contact:

Get all vms out of datastore

Post by dries.vergote »

Hi

How can I add vms to "Guest Processing -> Credentials... -> Guest OS Credentials".
We are user datastore in jobobject but for guest OS credentials I need to add vms to set credentials to it.

The part of setting the credentials I have already if I add the server through the GUI.

Thanks.
dries.vergote
Service Provider
Posts: 40
Liked: 5 times
Joined: Apr 24, 2015 2:51 pm
Full Name: Dries Vergote
Contact:

[MERGED] Get all vms out of datastore

Post by dries.vergote »

Hi
I would like to add all vm's in a datastore (added in job) to the guest OS credentials.
This is needed to specify the specific credentials of a vm. That part I already have with Set-VBRJobObjectVssOptions

Any idea how to accomplish this?
In the gui you can select the 'datastore and vms' and see only the vm's in that datastore.

thanks
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Get all vms out of datastore

Post by tdewin »

You can try this code

Code: Select all

$vmsandds = Find-VBRViEntity -DatastoresAndVMs
$ds = $vmsandds | ? { $_.name -eq "demo-fc" }
$vmsandds | ? { $_.Path.startswith($ds.path) -and $_.type -eq "Vm" }
(e.g "demo-fc" would be your datastore)
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Get all vms out of datastore

Post by tsightler »

If the job has a container object you'll have to manually enumerate and add the VM objects to the job to set the passwords for each. I usually use something like:

Code: Select all

# Get VMs by datastore and vms view
$vmsbydatastorepath = Find-VBRViEntity -DatastoresAndVMs | ?{$_.Type -eq "Vm"}
Then you can find VMs that belong to a datastore with:

Code: Select all

($vmsbydatastorepath | ?{$_.Path -like "*<datastore_name>*"})
Admittedly, this code does assume you will have only one Datastore with than name across the entire environment, if you have multiple vCenters with the possibility of duplicate datastore names you'd want to make sure to use the full path, this was more as a conceptual example, and approaches it pretty much the same way Timothy's code does.

Of course, you then still need to add those objects to the job and switch the object type of vssChild and then set the credentials. I've used code something like this in the past:

Code: Select all

write-host "Setting VSS Credentials for" $vm.Name
Add-VBRViJobObject -Job $job -Entities $vm | Out-Null
$newoij = Get-VBRJobObject -Job $Job -Name $vm.Name
$newoij.Info.Type = [Veeam.Backup.Model.CDbObjectInJobInfo+EType]::VssChild
Set-VBRJobObjectVssOptions -Object $newoij -Credentials $cred | Out-Null
dries.vergote
Service Provider
Posts: 40
Liked: 5 times
Joined: Apr 24, 2015 2:51 pm
Full Name: Dries Vergote
Contact:

Re: Get all vms out of datastore

Post by dries.vergote »

Thanks for the replies.
Indeed this works fine, I'll post update with full script when done.

For adding credentials per vm I got from Timotht to use another enum instead. Else you add it to the application only.

Code: Select all

[Veeam.Backup.Model.CDbObjectInJobInfo+EType]::GuestCredsChild
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests