Hi,
I've recently started looking at the SRM API for PowerCLI and, can get some quiet basic information, e.g. I can list VM's contained in a Protection Group.
Below is a script that I've been able to plagiarize to do this for me
$cred = Get-Credential
Connect-VIServer $vc -Credential $cred
Connect-SrmServer | Out-null
# Get the Protection Group Information & create a folder to save the results to
$ProtectionGroupName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the Name of the SRM Protection Group", "SRM Protection Group Name")
$ResultsFolder = New-Item -ItemType Directory -Path C:\Temp\$ProtectionGroupName -Force
$ResultsFile = "$Resultsfolder" + "\" + "$ProtectionGroupName" + " - " + (Get-Date -Format yyyy-MMM-dd-HHmm) + ".csv"
#Begin collecting data
$srmapi = $defaultsrmservers.ExtensionData
$srmpgs = $srmapi.protection.listprotectiongroups() | where {$_.GetInfo().Name -like "$ProtectionGroupName"} | Get-Unique
if (!($srmpgs))
{
Write-Host -ForegroundColor Red "Protection Group Name entered cannot be found"
Write-Host -ForegroundColor Red "Verify that you have entered a valid Protection Group Name. Exiting Script"
break
}
$pgvms =@()
$vms = $srmpgs.ListProtectedVMs()
for ($a=0; $a -lt $vms.Count; $a++)
{
$vm = get-vm -ID $vms[$a].VM.MoRef
$pgvms += $vm.Name
}
# sort the array alphabetically and enter the results into a .csv file
$pgvms = $pgvms | sort
Add-Content $ResultsFile $pgvms
# Disconnect from vCenter
Disconnect-VIServer $vc -Confirm:$false
# Open the .csv file
Invoke-Item $ResultsFile
I'd like to include extra information, Recovery Status, Priority, etc...
I've looked at the output from $srmapi.recovery, etc... but can't find what i'm looking for.
Anyone out there had any success with this already ?
Thanks
Did you already check the Site Recovery Manager API Developer's Guide to find these elusive properties ?
From there you might be able to find the method to use to get at them.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I tried the API Developers guide but either don't get any information or, get an error.
Eg.
$srmapi = $defaultsrmservers.ExtensionData
$srmapi | gm
$srmapi.Protection | gm
$srmapi.Protection.ListProtectedVms()
Exception calling "ListProtectedVms" with "0" argument(s): "Method 'ListProtectedVms' is not supported in SRM API version '2.0'"At line:1 char:1
+ $srmapi.Protection.ListProtectedVms()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
The API Version I have installed is 2.0
$srmapi.Content.ApiVersion
2.0
I'm running the following versions of the Snapin's
Get-PowerCLIVersion
PowerCLI Version
----------------
VMware vSphere PowerCLI 6.0 Release 1 build 2548067
---------------
Component Versions
---------------
VMWare AutoDeploy PowerCLI Component 6.0 build 2358282
VMWare ImageBuilder PowerCLI Component 6.0 build 2358282
VMware License PowerCLI Component 6.0 build 2315846
VMware vSphere PowerCLI Component 6.0 build 2548068
VMware vSphere Update Manager PowerCLI 6.0 build 2503190
and
$PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
Is it possible to upgrade the SRM API on a Client PC only and, not change anything on the SRM Server itself ?
It seems ListProtectedVMs was introduced in the v5 API.
Now if your SRM server doesn't support that version, there is no point in upgrading the client side, I guess.
But I could be wrong :smileyblush:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks LucD,
I think that I'll leave this for now, there's an entire environment upgrade being planned at the moment, going from 5.5 to 6.x
hopefully this will fix my issue (when it's finished)