Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

SMA Run book for enabling hyper-v replica after deployment in WAP

$
0
0

 

In Windows Azure Pack you have the ability to link your Automation runbooks to an "Event"

One of the common things that I see is about providing a disaster recovery solution to a customer especially in a multi tenant environment..

During VM creation we link our runbook to the Event as shown

Now everytime a virtual machine is created it will run my EnableHyperVReplicaVM runbook

 

In the runbook code we access a hidden variable called $PSPrivateMetaData

The important thing first is to get the VMM Job ID, as this allows us to monitor completion of the VMM Job before trying to enable hyper-v replica as otherwise it will fail!

Another part in this runbook is we use the Get-AutomationConnection to allow us to execute against the VMM server and use the Service management automation Assets to the fullest!

 

Anyway here is the code! And remember there are hundreds of other ways of doing this! J

 

workflowEnableHyperVReplicaforVM

{

 

$params=$PSPrivateMetaData.params

$VMMJobID=$PSPrivateMetaData.VMMJobId

 

$vmmserver=Get-AutomationConnection-Name'VMMConnection'

$SecurePassword=ConvertTo-SecureString-AsPlainText-String$vmmserver.Password -Force

$Credential=New-Object-TypeNameSystem.Management.Automation.PSCredential-ArgumentList$vmmserver.username, $SecurePassword

$replicaserver="svvmasp15.corp.contoso.com"

$masterserver="svvmasp16.corp.contoso.com"

 

$jobFinalState=InlineScript {

Import-ModuleVirtualMachineManager

 

 

While ((Get-SCJob-ID$USING:VMMJobId).Status -eq'Running')

{

$jobProgress= (Get-SCJob-ID$USING:VMMJobId).ProgressValue

Start-Sleep-Seconds3

}

 

$JobState= (Get-SCJob-ID$USING:VMMJobId).Status

Return$JobState

} -PSComputerName$VmmServer.ComputerName -PSCredential $Credential

 

$params=$params-split (',') -replace ('"','') -replace ('{','') -replace ('}','')

$vmname=InlineScript

{

 

Foreach ($pin$USING:params)

{

$key= ($p-split (':'))[0]

$value= ($p-split (':'))[1]

if(($key-eq"Name") -and ($value-ne"null"))

{

return$value

}

 

}

 

 

}

 

 

write-output"JobSate Result form VMM: $jobFinalstate"

write-output"VMName: $vmname"

 

$represult=inlinescript {

Import-ModuleHyper-V

Enable-VMReplication–VMName$using:vmname–ReplicaServerName$using:replicaserver–ReplicaServerPort80-authenticationtypekerberos

start-vminitialreplication-vmname$using:vmname

$result= (get-vm-name$using:vmname).ReplicationState

return$result

} -PSComputerName$masterServer-PSCredential$Credential

if ($represult-eq"Enabled")

{

$replicaenabled=$true

}

else

{

$replicaenabled=$false

}

 

 

 

 

write-output"ReplicaEnabledResult: $replicaenabled"

 

}

 

 

 


Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>