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.
LucD
can you suggest here ?
i used this
$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
last sync status
last sync size
any error/warning or configuration issuevms configured for replication but not in any protection group
any suggestion will be very helpful for me.
Hello LucD
can you suggest here.
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
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.
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