JBaileyTX
Contributor
Contributor

Best Resource for Best Practice Scripting for SRM?

Looking to improve my skills (and my sites) as fast as possible.

0 Kudos
2 Replies
praveenkv
Enthusiast
Enthusiast

Sample Scripts for your reference :

Create a Report of the Virtual Machines Associated with All Protection Groups:

1. List all protection groups associated with the SRM server.

$srmApi = $srm.ExtensionData

$protectionGroups = $srmApi.Protection.ListProtectionGroups()

2.Generate a report of the virtual machines associated with all protection groups.

$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 | %{

        $output = "" | select VmName, PgName

        $output.VmName = $_.Name

        $output.PgName = $protectionGroupInfo.Name

        $output

    }

} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Protect a Virtual Machine

You can protect a virtual machine by replicating it to a remote SRM site.

1. Connect to the vCenter Server system that the SRM server is registered with.

Connect-VIServer -Server vc3.example.com -User 'MyAdministratorUser' -Password 'MyPassword'

2.Establish a connection to the local SRM server by providing credentials to the remote SRM site.

$srm = Connect-SrmServer -RemoteUser 'MyRemoteUser' -RemotePassword 'MyRemotePassword'

3.List all protection groups associated with the SRM server.

$srmApi = $srm.ExtensionData

$protectionGroups = $srmApi.Protection.ListProtectionGroups()

4.Associate the TestVM virtual machine with the ProtGroup1 protection group and enable the protection for that virtual machine.

$vmToAdd = Get-VM "TestVM"

$targetProtectionGroup = $protectionGroups | where {$_.GetInfo().Name -eq "ProtGroup1" }

$targetProtectionGroup.AssociateVms(@($vmToAdd.ExtensionData.MoRef))

# Enable protection for that virtual machine

$protectionSpec = New-Object VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionSpec

$protectionSpec.Vm = $vmToAdd.ExtensionData.MoRef

$protectTask = $targetProtectionGroup.ProtectVms($protectionSpec)

while(-not $protectTask.IsComplete()) { sleep -Seconds 1 }

-----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos
JBaileyTX
Contributor
Contributor

Thank you for the response!!  These look like exactly what I'll need when I learn how to read them.  However, I'm needing to start a few steps back.  :smileyblush:

I am looking for free or very inexpensive books or training on how to develop scripting skills very nearly from scratch.

0 Kudos