VMware Cloud Community
piercj2
Enthusiast
Enthusiast
Jump to solution

SRM Protected VMs

Hi,

I'm trying to get a list of the Protected VM's in SRM.

I've looked through the discussions already and, thanks to earlier posts and, the SRM API, I've come up with the attached script

The script works but, I gave 2 issues I need help clearing up.

1. the output format

The CSV that is output has the Protection Group Name at the far left column and then each subsequent column contains a VM name, e.g.

Protection GroupVM0 NameVM1 NameVM2 NameVM3 Name
Application PGappserver1appserver2appserver3appserver4
Database PGdbserver1dbserver2dbserver3
Random PGRandomserver1Randomserver2

I'd like to group the output per Protection Group. I've tried using group-object but, can't get it to do what i'm looking for

2. Missing VM's

in the output on the ISE, I get a lot of

get-vm : 03/Oct/2016 17:49:26 Get-VM VM with id 'VirtualMachine-vm-41696' was not found using the specified filter(s)

When I search for the VM using Get-VM -ID *vm-41696 nothing is returned.

The result is I might have a Protection listed in the output file with no VM's listed next to it.

When I check the Protection Group in SRM, there are VM's there

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

1) Not exactly sure what you mean by "... per protection group"?

Can you perhaps show a mock-up layout of the desired format?

2) Do the VMs for which you get the errors still exist?

Or have they been recreated?

In other words, is the MoRef of the current VM with the same name, the same as the MoRef of the VM in SRM?

Your script looks ok, just made a few small changes to avoid the complex indexing.

$logfolder = "C:\Temp\SRM_PGs"

set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null

#############################

if (!(Test-Path -Path $logFolder)) {

    New-Item -ItemType Directory -Path $logFolder

}

Set-Location -Path $logFolder

$logfile = (Get-Date -Format yyyy-MMM-dd-HHmm) + "-SRMProtectedVMs.csv"

$report=@()

connect-viserver -Server $vcenter -username $vcuser -password $vcpass|out-null

Connect-SrmServer |out-null

$srmapi = $defaultsrmservers.ExtensionData

$srmpgs = $srmapi.protection.listprotectiongroups()

foreach ($pg in $srmpgs){

    $pgname = $pg.GetInfo().Name

    $vms = $pg.ListProtectedVMs()

    $ArrayProp=[ordered]@{

        'Protection Group'=$pgname;

    }

    foreach($srmVm in $pg.ListProtectedVMs()){

        $vm = Get-View -ID $srmVm.VM.MoRef -Property Name

        $ArrayProp.Add("VM$($a) Name",$vm.Name)

    }

   

    $report += New-Object -TypeName psobject -Property $ArrayProp

}

$report |

    Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending |

    Export-Csv $logfile -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

1) Not exactly sure what you mean by "... per protection group"?

Can you perhaps show a mock-up layout of the desired format?

2) Do the VMs for which you get the errors still exist?

Or have they been recreated?

In other words, is the MoRef of the current VM with the same name, the same as the MoRef of the VM in SRM?

Your script looks ok, just made a few small changes to avoid the complex indexing.

$logfolder = "C:\Temp\SRM_PGs"

set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null

#############################

if (!(Test-Path -Path $logFolder)) {

    New-Item -ItemType Directory -Path $logFolder

}

Set-Location -Path $logFolder

$logfile = (Get-Date -Format yyyy-MMM-dd-HHmm) + "-SRMProtectedVMs.csv"

$report=@()

connect-viserver -Server $vcenter -username $vcuser -password $vcpass|out-null

Connect-SrmServer |out-null

$srmapi = $defaultsrmservers.ExtensionData

$srmpgs = $srmapi.protection.listprotectiongroups()

foreach ($pg in $srmpgs){

    $pgname = $pg.GetInfo().Name

    $vms = $pg.ListProtectedVMs()

    $ArrayProp=[ordered]@{

        'Protection Group'=$pgname;

    }

    foreach($srmVm in $pg.ListProtectedVMs()){

        $vm = Get-View -ID $srmVm.VM.MoRef -Property Name

        $ArrayProp.Add("VM$($a) Name",$vm.Name)

    }

   

    $report += New-Object -TypeName psobject -Property $ArrayProp

}

$report |

    Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending |

    Export-Csv $logfile -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
piercj2
Enthusiast
Enthusiast
Jump to solution

Thanks Luc,

Removing the Indexing was a big help and it cleaned it up nicely.

I couldn't get the last foreach loop to work as the $a had not been declared earlier in the script

    foreach($srmVm in $pg.ListProtectedVMs()){

        $vm = Get-View -ID $srmVm.VM.MoRef -Property Name

        $ArrayProp.Add("VM$($a) Name",$vm.Name)

    }

I tried various combinations of [array]::IndexOf but couldn't get it to work.

For this reason I switched back to

   for ($a=0; $a -lt $pgvms.Count; $a++) {

      $vm = get-vm -ID $pgvms[$a].VM.MoRef -ErrorAction SilentlyContinue

      $ArrayProp.Add("VM$($a) Name",$vm.Name)

    }

I added -ErrorAction SilentlyContinue when I realized that the earlier errors I was getting were a result of the Placeholder VM's at the SRM location where I was running the script. Because they are only placeholders, the script was erroring on $vm = Get-View -ID $srmVm.VM.MoRef -Property Name

The format of the output is actually working well for what I now need.

My only remaining issue is that ListAssociatedVMs() doesn't seem to work. I saw from earlier posts that this seems to be a common issue, you contributed to these Posts also but so far there's no solution identified.

Is there any way of identifying if a VM is not Protected without ListAssociatedVMs() ?

The most recent copy of my script is attached.

Thanks,

Jason

0 Kudos