This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-pg-info.ps1
83 lines (65 loc) · 2.95 KB
/
list-pg-info.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<#
.SYNOPSIS
List VMs in a Protection Group
.DESCRIPTION
.PARAMETER SrmServer
The domain name of the protected site SRM server to connect to
.PARAMETER UserName
.PARAMETER Password
.PARAMETER VmName
The id of the VM to add to the VR protection group. E.g. 'vm-108'
.EXAMPLE
.LINK
https://github.com/benmeadowcroft/BCO5652
#>
param (
[string] $SrmServer = 'localhost',
[string] $UserName = 'Administrator',
[string] $Password = 'VMware1!'
)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} # ignore untrusted SSL certificate
Write-Host "Connecting to SRM"
$webSvc = New-WebServiceProxy ("https://" + $SrmServer + ":8095/srm-Service?wsdl") -Namespace SRM
$srm = New-Object SRM.SrmService
$srm.Url = "https://" + $SrmServer + ":9007"
$srm.Timeout = 600000
$srm.CookieContainer = New-Object System.Net.CookieContainer
$srmSvcRef = New-Object SRM.ManagedObjectReference
$srmSvcRef.Type = "SrmServiceInstance"
$srmSvcRef.Value = $srmSvcRef.Type
$srmSvcContent = $srm.RetrieveContent($srmSvcRef)
Write-Host "Log in to SRM"
$srm.SrmLoginLocale($srmSvcRef, $UserName, $Password, $null)
$srmObject = New-Object System.Object
$srmObject | Add-Member -Type NoteProperty -value $SrmServer -Name SRMServer
$srmObject | Add-Member -Type NoteProperty -value $srm -Name SRMService
$srmObject | Add-Member -Type NoteProperty -value $srmSvcContent -Name SRMContent
$protectionGroupList = @();
#Get Information about the ProtectionGroups and combine them
ForEach ($protectionGroup in $SrmObject.SRMService.ListProtectionGroups($SrmObject.SRMContent.Protection)) {
Write-Host "Fetching ProtectionGroupInfo"
$protectionGroupInfo = $SrmObject.SRMService.GetInfo($protectionGroup)
Write-Host "Fetching VMs for ProtectionGroup"
$protectedVms = $SrmObject.SRMService.listProtectedVms($protectionGroup)
$customProtectionGroupInfo = New-Object System.Object
$customProtectionGroupInfo | Add-Member -Name ProtectionGroupMoRef -Value $protectionGroup -MemberType NoteProperty
$customProtectionGroupInfo | Add-Member -Name ProtectionGroupInfo -Value $protectionGroupInfo -MemberType NoteProperty
$customProtectionGroupInfo | Add-Member -Name ProtectedVms -Value $protectedVms -MemberType NoteProperty
$protectionGroupList += $customProtectionGroupInfo
}
Write-Host "\nProtection Groups:"
ForEach ($pg in $protectionGroupList) {
Write-Host " | ProtectionGroup: " $pg.protectionGroupInfo.name
Write-Host " +-- Description: " $pg.protectionGroupInfo.description
Write-Host " +-- Replication Type: " $pg.protectionGroupInfo.type
Write-Host " +-+ Virtual Machines:"
ForEach ($vm in $pg.protectedVms) {
Write-Host " | VM MoId: " $vm.vm.value
Write-Host " +-- Protection State: " $vm.state
Write-Host " +-- Peer State: " $vm.peerState
Write-Host " +-- Needs Configuration: " $vm.needsConfiguration
Write-Host " |"
}
}
Write-Host "Log out of SRM"
$srm.SrmLogoutLocale($srmSvcRef);