With the SRM PowerCLi cmdlets, I see it is possible to get a list of all VMs in a protection group. But if I just have the name of one VM, how can I query SRM and find out the protection group it is in? Is this possible?
Thanks!
Code given by Lucd works. it just needs a little tweak to update the metadata. once you run the below function, it updates the values so you can see the protection group details.
$protectedVms = $protectionGroup.ListProtectedVms()
$protectedVms | % { $_.Vm.UpdateViewData() }
here is some of the scripts i created to replace SRM tool with powershell. one of the scripts in there has this function and can be used to export all the data from SRM to a csv which later can be used to recover all the virtual machines without SRM.
https://www.linkedin.com/pulse/powershell-scripts-recover-mission-critical-you-do-have-vamshi-meda
Afaik there is no such method, but you can of course scan all groups for that VM.
Something like this
$vmName = 'MyVM'
$srm = Connect-SrmServer -RemoteCredential $cred
foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){
Get-VM -id $($group.ListAssociatedVMs().MoRef) |
where{$_.Name -eq $vmName} |
Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok great - thanks again. My script errored out though - any ideas?
Exception calling "ListAssociatedVms" with "0" argument(s): "The operation is not supported on the object."
At line:5 char:18
+ Get-VM -id $($group.ListAssociatedVMs().MoRef) |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Get-VM : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At line:5 char:16
+ Get-VM -id $($group.ListAssociatedVMs().MoRef) |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Do you happen to have empty protection groups?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure -there might be - but most are filled, and I'm getting this set of error messages 50 times or so in repetition with no successful output of data even for the protection group I know this VM happens to be in.
Any other ideas?
Try like this
$vmName = 'MyVM'
$srm = Connect-SrmServer -RemoteCredential $cred
foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){
Get-VM -id $($group.ListProtectedVMs().VM.MoRef) |
where{$_.Name -eq $vmName} |
Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there any way to suppress the warning output in the PowerShell ISE for all the Protection Groups that do not contain the VM Name ?
I've tried ErrorAction and Warning Action but the Red Text is displayed in the ISE for all Protection Groups that don't contain a particular VM.
Perhaps something like try/catch ?
$srm = Connect-SrmServer -Credential $cred
$vmName = 'MyVM'
foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){
Try {
Get-VM -id $($group.ListProtectedVMs().VM.MoRef) |
where{$_.Name -eq $vmName} |
Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}
}
Catch {
* > $null
}
}
Thanks
Code given by Lucd works. it just needs a little tweak to update the metadata. once you run the below function, it updates the values so you can see the protection group details.
$protectedVms = $protectionGroup.ListProtectedVms()
$protectedVms | % { $_.Vm.UpdateViewData() }
here is some of the scripts i created to replace SRM tool with powershell. one of the scripts in there has this function and can be used to export all the data from SRM to a csv which later can be used to recover all the virtual machines without SRM.
https://www.linkedin.com/pulse/powershell-scripts-recover-mission-critical-you-do-have-vamshi-meda
ok thanks all for the input