PowerShell script exchange
Post Reply
Deon
Veeam Software
Posts: 25
Liked: 9 times
Joined: Jun 26, 2014 7:02 pm
Full Name: Denis Churaev
Location: Bucharest, Romania
Contact:

[Script] Find DNS name of online Hyper-V VMs in jobs

Post by Deon »

As a result of my attempt to assist a forum user, I found myself writing this script.
Maybe it could be useful to someone else, or you could link people to it.

I have created a test job called "Backup job for Andersgustaf" with two VMs:
- one online (winserver2012_aama)
- one offline (New Virtual Machine1).

The job must run at least once to collect guest OS info. For Hyper-V you don't have to enable application-aware processing, we will get this info anyway. For VMware I haven't tested yet, I will update the post tomorrow accordingly.
The machines must be online and have integration tools installed, so that the host could get guest OS properties via Data Exchange service.

Please replace "YourJobName" with the actual name of the job.

Code: Select all

filter Invoke-Method {
    param(
        [String]$Method,

        [Object[]]$ArgumentList
    )

    $_.GetType().InvokeMember(
        $Method.Trim(),
        ([System.Reflection.BindingFlags]'InvokeMethod'),
        $null,
        $_,
        $ArgumentList
   )
}
clear

add-pssnapin Veeampssnapin
$job = get-vbrjob -name "YourJobName"
$vms = Get-VBRJobObject -job $job

foreach ($vm in $vms) {
    $dnsname = $vm.object.info.guestinfo | Invoke-Method FindDnsName
    $name = $vm.object.name
    write-host "Object in job: $name, DNS name: $dnsname"
}
Output for my case:
Image
Deon
Veeam Software
Posts: 25
Liked: 9 times
Joined: Jun 26, 2014 7:02 pm
Full Name: Denis Churaev
Location: Bucharest, Romania
Contact:

Re: [Script] Find DNS name of online Hyper-V VMs in jobs

Post by Deon »

Here's the modified version of the script, which retrieves most of the useful Guest OS info.

It works for both Hyper-V and VMWare jobs, but Veeam must have already collected the VM info (for VMWare it means that Application aware processing/Guest indexing must be enabled).

Replace "Job Name" with your job's name.

Code: Select all

add-pssnapin Veeampssnapin
$job = get-vbrjob -name "Job Name"
$vms = Get-VBRJobObject -job $job
clear

foreach ($vm in $vms) {
    $dnsname = $vm.object.info.guestinfo.GetType().InvokeMember("FindDnsName",([System.Reflection.BindingFlags]'InvokeMethod'),$null,$vm.object.info.guestinfo,$null)
    $os = $vm.object.info.guestinfo.GetType().InvokeMember("GetGuestOsName",([System.Reflection.BindingFlags]'InvokeMethod'),$null,$vm.object.info.guestinfo,$null)
    $ipv4 = $vm.object.info.guestinfo.GetType().InvokeMember("GetIpv4Addresses",([System.Reflection.BindingFlags]'InvokeMethod'),$null,$vm.object.info.guestinfo,$null)
    $name = $vm.object.name
    write-host "Object in job: $name, DNS name: $dnsname, IPv4 address: $ipv4, GuestOS: $os"
}
Example:
Image
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests