VMware Cloud Community
piyushranusri
Enthusiast
Enthusiast

SRM Reporting_Powersehell

Can some one share me working script for SRM reporting where i can export

protection group, vm name, any error and last sync date and sync size.  is this correct what am trying. we do have 15 datacenter, i know that will take some time. So that is not an issue.

Import-Module VMware.VimAutomation.Vds
Import-Module -Name "C:\Windows\addins\SRM\SRM-Cmdlets-master\Meadowcroft.Srm.Protection.ps1"
$vcenterip=
foreach ($vcenter in $vcenterip){
Write-Output 'Before connecting'
Connect-VIServer -Server "$vcenter" -User xxxxxxxx -Password xxxxxxxx
Write-Output "Connected to $vcenter"
$logfolder = "C:\Windows\addins\SRM\Results\"
#connect-viserver -Server $vcenter -username $vcuser -password $vcpass|out-null
#Connect-SrmServer |out-null
$srmapi = $defaultsrmservers.ExtensionData
$srmpgs = $srmapi.protection.listprotectiongroups()
for ($i=0; $i -lt $srmpgs.Count; $i++)
{
$vms = $srmpgs[$i].ListProtectedVMs()
$pgvms = [array] "Virtual Machine list:"
for ($a=0; $a -lt $vms.Count; $a++)
{
 
$vm = get-vm -ID $vms[$a].VM.MoRef
$pgvms += $vm.Name
}
$pgname = $srmapi.protection.listprotectiongroups()[$i].GetInfo().Name
add-content $logfile "==================================================================================="
add-content $logfile "******************************Next Protection Group********************************"
add-content $logfile "==================================================================================="
$text = "The following " + $vms.Count + " virtual machines are in the Protection Group named " + $pgname
add-content $logfile $text
add-content $logfile $pgvms
}
disconnect-viserver -Server $vcenter -confirm:$false
$report | Export-Csv -NoTypeInformation "$outputfile"
0 Kudos
6 Replies
piyushranusri
Enthusiast
Enthusiast

LucD

can you suggest here ?

0 Kudos
piyushranusri
Enthusiast
Enthusiast

i used this

Get-SrmProtectionGroup | %{

   $pg = $_

   Get-SrmProtectedVM -ProtectionGroup $pg } | %{

   $output = "" | select VmName, PgName

   $output.VmName = $_.Vm.Name

   $output.PgName = $pg.GetInfo().Name

   $output

  } | Format-Table @{Label="VM Name"; Expression={$_.VmName} },

   @{Label="Protection group name"; Expression={$_.PgName}

}

but its shows only vms are in protection group.

trying to include more details like

Vms last sync date

last sync status

last  sync size

any error/warning or configuration issue

vms configured for replication but not in any protection group

any suggestion will be very helpful for me.

0 Kudos
piyushranusri
Enthusiast
Enthusiast

Hello LucD
can you suggest here.

0 Kudos
LucD
Leadership
Leadership

I don't know SRM and its API well enough.

But I suggest to open an Issue at the SRM module  repo, Ben might be able to help you.


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

0 Kudos
piyushranusri
Enthusiast
Enthusiast

i tried on the community week ago but no response. trying to understand the properties in HOL.

once that done, sure i will update here.

0 Kudos
piercj2
Enthusiast
Enthusiast

Try this, it's worked for me

# Clear initial variables

$vCenters = $null

$vc = $null

$logfolder = $null

$outputfile = $null

$srmDailyReport = $null

# set location of output data

$logfolder = "C:\Temp\SRM_PGs"

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

    New-Item -ItemType Directory -Path $logFolder

}

Set-Location -Path $logFolder

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

$srmDailyReport=@()

# Create array with vCenter Names, add/change vCenters as necessary

[string[]] $vCenters = "vcsa1.comp.com", "vcsa2.comp.com"

foreach ($vc in $vCenters) {

      

   

    # Clear variables

    $srmConnection = $null

    $srmApi = $null

    $protectionGroupInfo = $null

    $protectionGroups = $null

    $protectionGroup = $null

    $protectedVms = $null

    $associatedVms = $null

    $vm = $null

    $VmNeedsSrmConfig = $null

    $RecoveryPlan = $null

    $view = $null

   

    Connect-VIServer $vc -username "comp\USERNAME" -password "notThisPassword!"

    Connect-SrmServer -User "comp\USERNAME" -Password "notThisPassword!" -OutVariable srmConnection

    $srmIP = $srmConnection.Name

    $srmServerName = ([System.Net.dns]::GetHostEntry($srmIP)).HostName

   

    $srmApi = $srmConnection.ExtensionData

    $protectionGroups = $srmApi.Protection.ListProtectionGroups()

   

    # Begin TEST BLOCK

    # To run script on an individual Protection Group, uncomment two lines below (comment out line 72 if testing)

    #$TestProtectionGroup = $protectionGroups | where {$_.GetInfo().Name -eq "Archer" }

    #$TestProtectionGroup | where {$_.GetProtectionState() -ne "Shadowing" } | % {

    # End TEST BLOCK

   

    # If a Protection Group has a status of Shadowing, no data exists within this local SRM Server. Connect to alternate SRM Server and proceed

    # If a Protection Group has a status of Recovered or Ready, proceed to collect local data

    # Comment out the below line when testing using individual Protection Groups

    $protectionGroups | where {$_.GetProtectionState() -ne "Shadowing" } | % {

       

            $protectionGroup = $_

            $protectionGroupInfo = $protectionGroup.GetInfo()

            $RecoveryPlan = $protectionGroup.ListRecoveryPlans()

               

        # If a Protection Group has a status of Recovered, update available fields

        if ($protectionGroup.GetProtectionState() -eq "Recovered") {

            $GeneralProp = [ordered]@{

                'Production Cluster'=""

                'Protection Group' = $protectionGroupInfo.Name

                'Recovery Plan Name' = $RecoveryPlan.GetInfo().Name

                'Needs SRM Config' = 'Reprotect Needed'

            }

            $srmDailyReport += New-Object -TypeName psobject -Property $GeneralProp

        }

        # If a Protection Group has a status of Ready, update available fields

        else{   

            # To get all VM's in the Protected Datastore, this should be all VM's associated with Protection Group

            $associatedVms = $protectionGroup.ListProtectedDatastores() | Get-VIObjectByVIView | Get-VM

            # The following lists the virtual machines protected by a Protection Group

            $protectedVms = $protectionGroup.ListProtectedVms()

            # The result of the above call is an array of references to the virtual machines at the vSphere API

            # To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object

            $protectedVms | % { $_.Vm.UpdateViewData() }

               

           

            foreach ($vm in $associatedVms) {

                $GeneralProp = [ordered]@{}

                $GeneralProp.Add('Production Cluster',$vm.VMHost.Parent.Name)

                $GeneralProp.Add('Protection Group',$protectionGroupInfo.Name)

                $GeneralProp.Add('Recovery Plan Name' , $RecoveryPlan.GetInfo().Name)   

      

       

                $VmNeedsSrmConfig = $protectedVms | where {$protectedVms.vm.name -eq $vm.Name}

                if ($VmNeedsSrmConfig.needsconfiguration){

                    $GeneralProp.Add('Needs SRM Config','')

                }

                else{

                    $GeneralProp.Add('Needs SRM Config','VM Needs Config')

                }

                $GeneralProp.Add('Vm Name' , $vm.name)

                $GeneralProp.Add('Guest O/S' , $vm.GuestId)

      

                $view = $vm | Get-View

                    $vmxfile = $view.Config.Files.VmPathName

                    $vmxLocation = $vmxfile.split(" ")[0].TrimStart("[").TrimEnd("]")

                    $GeneralProp.Add(".vmx Location", $vmxLocation)

                    $GeneralProp.Add("Tools Recommendation", $view.Guest.ToolsVersionStatus)

       

      

                $srmDailyReport += New-Object -TypeName psobject -Property $GeneralProp

  

            } # close "foreach ($vm in $associatedVms)"

        } # close else

    } # close "$protectionGroups | where {$_.GetProtectionState() -ne "Shadowing" }"

   

    Disconnect-VIServer -Server $vc -Confirm:$false -Force

} # close "foreach ($vc in $vCenters)"

# Create the .csv file

$srmDailyReport |

    Sort-Object -Property 'Protection Group', 'Vm Name' |

    Export-Csv $outputfile -NoTypeInformation

   

Invoke-Item $outputfile

0 Kudos