0 Replies Latest reply on Sep 1, 2017 8:03 AM by oldschoola41

    SRM Protection Group Export List Report + Replication Status Powershell script

    oldschoola41 Lurker

      for a while i was looking for a decent report to export all vm's in ALL protection groups with the information i needed(notes, cpu , etc).

       

      One of the guys I work with created a script that does just that.  Here it is below and attached.

      This script gives you all vm's in all protection groups as well as if they are being replicated and the status of that replication.  Along with some other handy info(cpu/notes/memory etc)

      Enjoy and share!

       

      Ran on latest version of srm to date.

       

      you can run it by typing this at the ps cli:

      .\SRM3.ps1 -Server "vcenter-servername" -CSVPath "C:\file.csv"

       

      param ($Server = $Server,

      $CSVPath = $CSVPath)

      $username = Read-Host "Enter your username"

      $password = Read-Host -AsSecureString "Enter your password"

      $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)

      $value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

      try

      {

      Connect-VIServer -Server $Server -User $username -Password $value -ErrorAction Stop

      }

      catch

      {

      $_.Exception.Message

      break

      }

      $srm = Connect-SrmServer

      $srmApi = $srm.ExtensionData

      $protectionGroups = $srmApi.Protection.ListProtectionGroups()

      [string]$outfile = $protectionGroups | % {

      $protectionGroup = $_

       

      $protectionGroupInfo = $protectionGroup.GetInfo()

       

      # The following command lists the virtual machines associated with a protection group

      $vms = $protectionGroup.ListAssociatedVms()

       

      # 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

      $vms | % { $_.UpdateViewData() }

      # After the data is populated, use it to generate a report

      $vms | %{

      # This declare the VM name and gets all properties

      $vmname = $_.Name

      if ($vmname)

      {

      $vminfo = Get-VM $vmname -ErrorAction SilentlyContinue | select *

      if ((($vminfo.extensiondata.config.extraconfig.Key) -eq "hbr_filter.destination") -and (($vminfo.extensiondata.config.extraconfig.Key) -eq "hbr_filter.rpo"))

      {

      $replication = "Replication configured"

      }

      else { $replication = "Replication not configured" }

      if (($vminfo.extensiondata.config.extraconfig.Key) -eq "hbr_filter.pause")

      {

      $replicationPaused = "Yes"

      }

      else { $replicationPaused = "No" }

      }

      $output = "" | select VmName, PgName, Notes, PowerState, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHost, Folder, UsedSpaceGB, ProvisionedSpaceGB, ReplicationConfig, ReplicationPause

      $output.VmName = $_.Name

      $output.PgName = $protectionGroupInfo.Name

      $output.PowerState = $vminfo.PowerState

      $output.Notes = $vminfo.Notes

      $output.Guest = $vminfo.Guest

      $output.NumCpu = $vminfo.NumCpu

      $output.CoresPerSocket = $vminfo.CoresPerSocket

      $output.MemoryMB = $vminfo.MemoryMB

      $output.MemoryGB = $vminfo.MemoryGB

      $output.VMHost = $vminfo.VMHost

      $output.Folder = $vminfo.Folder

      $output.UsedSpaceGB = $vminfo.UsedSpaceGB

      $output.ProvisionedSpaceGB = $vminfo.ProvisionedSpaceGB

      $output.ReplicationConfig = $replication

      $output.ReplicationPause = $replicationPaused

      $output

      }

      } | Select-Object @{ Label = "VM Name"; Expression = { $_.VmName } }, @{ Label = "VM Notes"; Expression = { $_.Notes } }`

      , @{ Label = "PowerState"; Expression = { $_.PowerState } }, @{ Label = "Guest"; Expression = { $_.Guest } }, @{ Label = "NumCpu"; Expression = { $_.NumCpu } }`

      , @{ Label = "CoresPerSocket"; Expression = { $_.CoresPerSocket } }, @{ Label = "MemoryMB"; Expression = { $_.MemoryMB } }`

      , @{ Label = "MemoryGB"; Expression = { $_.MemoryGB } }, @{ Label = "VMHost"; Expression = { $_.VMHost } }, @{ Label = "Folder"; Expression = { $_.Folder } }`

      , @{ Label = "UsedSpaceGB"; Expression = { $_.UsedSpaceGB } }, @{ Label = "ProvisionedSpaceGB"; Expression = { $_.ProvisionedSpaceGB } }`

      , @{ Label = "Protection group name"; Expression = { $_.PgName } }, @{ Label = "Replication Status"; Expression = { $_.ReplicationConfig } }`

      , @{ Label = "Replication Paused"; Expression = { $_.ReplicationPause } } | Export-Csv $CSVPath -NoTypeInformation -Append