none
Excluding VM's from cluster when auto adding them to Protection Groups in dpm2012r2 RRS feed

  • Question

  • Our environment:

    2 DPM 2012 r2 servers sitting atop a CSV. 1 for Dev VM's and the other for Production VM's. DB's for both on a remote SQL 2012 server.

    Problem:

    New VM's are being added constantly to our Hyper-V cluster and I'd like to protect these without having to do a manual audit. I found a script called AddNewClusteredVM.ps1 that tackles this problem . I've tried and tested on our dev cluster and it works like a charm. I'd like to modify the script so it excludes some machines from inquiries. These are mostly template vm's or ones I don't want protected.

    Need help adding exclusion parameters to the script so it excludes machines:

    # AddNewClusteredVM.ps1

    # 1. Parameters supplied to the script
    param([string] $ProductionCluster = "", [string] $PGName = "") 

    # 2. Failures are registered in Applocation events in the DPM server.
    trap [Exception] { 
    $log = Get-EventLog -List | Where-Object { $_.Log -eq "Application" }
    $log.Source = "AddNewClusteredVM"
    $log.WriteEntry("TRAPPED: $error[0]", [system.Diagnostics.EventLogEntryType]::Error,9911) 
    $Error[0] #show on console
    exit 
    }

    # 3. Prompt for missing parameters
    if(!$ProductionCluster) 
    {
    $Productioncluster = read-host "Enter the cluster FQDN "
    }
    if(!$PGName) 
    {
    $PGName = read-host "Enter the name of your existing Hyper-V protection group "
    }

    $dpmservername = &"hostname"
    connect-dpmserver $dpmservername

    # Do not modify this line
    $tape = "Short-term using tape"

    # Hyper-V Writer guid
    $guid = "66841cd4-6ded-4f4b-8f17-fd23f8ddc3de"

    # 4. Search for the protection group name passed as input and exit if it was not found
    $PGList = @(Get-ProtectionGroup $dpmservername)
    $PG = $PGlist | where { $_.FriendlyName -eq $PGName}
    if (!$PG) { Throw "Specified protection group [$PGname] is not found!" }

    # 5. Obtain the list of protected clusters on this DPM server
    $Cluster = Get-ProductionCLuster $dpmservername | ? { $_.ClusterName -eq $ProductionCluster}
    if (!$Cluster) { Throw "Specified cluster name  [$ProductionCluster] is not found!" }

    $RGList = @()
    $joblist = @()
    $global:DSlist = @()

    # 6. Run inquiry on cluster to get list of available resource groups
    write-host "Running Inquiry on" $Cluster.clusterName
    $RGlist = Get-ProductionVirtualName $Cluster

    # 7. Need to run inquiry on each resource group
    foreach ($RG in $RGlist)
    {
    write-host "Running Inquiry on" $RG.NetBiosName
    # 7.1 Inquiry is run in parallel and the event mechanism is used to signal completion of inquiry.
    # 'DataSourceDetectionEvent' event signals the completion of inquiry. and the data sources obtained are added to the global variable
    $joblist += register-objectevent -inputobject $RG -Eventname DatasourceDetectionEvent -Action {$global:DSlist += $($Event.SourceEventArgs.ProtectableObjects)}

    # 7.2 Run inquiry
    Get-Datasource -ProductionServer $RG -Inquire -Async
    }

    # 8. Scan through each job created in the previous loop
    foreach ($job in $joblist)
    {
    # 8.1 Waiting for the job to run
    while ($job.State -eq "NotStarted")
    {
    write-host "Waiting for inquiry to complete" $global:DSlist.count "item(s) obtained..."
    sleep 1
    }
    }
    # 8.2 Inquiry complete on all resource groups

    write-host "Inquiry listed" $global:DSlist.count "item(s)..."

    # 9. If object is a data source and of type Hyper-V and is currently not protected add to list of unprotected VMs
    $unprotectedDSList = @(($global:DSList) | ? {$($_.Type.IsDatasource) -and ($($_.Type.Id) -match $guid) -and ! $($_.Protected)})

    # 10. Exit if there are no unprotected VMs
    if ($unprotectedDSList.count -lt 1) 
    {
    write-host "No new datasources found!"
    exit 1
    }

    # 11. Obtain a modifiable protection group type
    $MPG = Get-ModifiableProtectionGroup $PG

    # 12. Perform the following for each new VM to add to protection
    foreach ($ds in $unprotectedDSList)
    {
    write-host "Adding data source" $ds.Name "to" $MPG.FriendlyName
    $npg = Add-ChildDatasource -ProtectionGroup $MPG -ChildDatasource $ds

    # 12.1 Disk Allocation is skipped in case of short term protection being to tape.
    if($MPG.protectionmethod -eq $tape) {continue;}
    $x = Get-DatasourceDiskAllocation -Datasource $ds
    Set-DatasourceDiskAllocation -Datasource $ds -ProtectionGroup $MPG
    }

    # 13 Note that this step will force immediate replica creation irrespective of the PG policy.
    Set-ReplicaCreationMethod -ProtectionGroup $MPG -Now

    write-host "Adding new Hyper-V data sources to" $MPG.FriendlyName

    # 14 Save the changes to the protection group. Replica creation will be triggered immediately.
    Set-protectiongroup $MPG

    disconnect-dpmserver $dpmservername -erroraction silentlycontinue
    "Exiting from script"






    Thursday, July 23, 2015 6:47 PM

All replies

  • I'm starting to think it can't be done. I've tried adding it in different places and without a sound way of knowing where, i'm still at a loss.

    Wednesday, July 29, 2015 2:13 PM
  • I changed the  script for DPM 2016 with an exlusion option

    # AddNewClusteredVMtoDPMv2.ps1
    # This script is expected to work with DPM 2016
    
    # 1. Parameters supplied to the script
    param([string] $ClusterFQDN = "", [string] $ProtectionGroup = "", [string] $DiskStorage = "", [string[]] $DoNotAdd = @()) 
    
    # 2. Failures are registered in Applocation events in the DPM server.
    trap [Exception] { 
    	$log = Get-EventLog -List | Where-Object { $_.Log -eq "Application" }
    	$log.Source = $MyInvocation.MyCommand.Name
    	$log.WriteEntry("TRAPPED: $error[0]", [system.Diagnostics.EventLogEntryType]::Error,9911) 
    	$Error[0] #show on console
    	exit 
    }
    
    # 3. Prompt for missing parameters
    if(!$ClusterFQDN) 
    {
    	$ClusterFQDN = read-host "Enter the cluster FQDN "
    }
    if(!$ProtectionGroup) 
    {
    	$ProtectionGroup = read-host "Enter the name of your existing Hyper-V protection group "
    }
    
    $dpmservername = &"hostname"
    Connect-DPMServer -DPMServerName $dpmservername
    
    # Do not modify this line
    $tape = "Short-term using tape"
    
    # 4. Search for the protection group name passed as input and exit if it was not found
    $PGList = @(Get-DPMProtectionGroup $dpmservername)
    $PG = $PGlist | where { $_.FriendlyName -eq $ProtectionGroup}
    if (!$PG) { Throw "Specified protection group [$ProtectionGroup] is not found!" }
    
    # 5. Obtain the list of protected clusters on this DPM server
    $Cluster = Get-DPMProductionCluster -DPMServerName $dpmservername | ? { $_.ClusterName -eq $ClusterFQDN}
    if (!$Cluster) { Throw "Specified cluster name  [$ClusterFQDN] is not found!" }
    
    $RGList = @()
    $joblist = @()
    $global:DSlist = @()
    
    # 6. Run inquiry on cluster to get list of available resource groups
    write-host "Running Inquiry on $($Cluster.clusterName) (" -NoNewLine
    $RGlist = Get-DPMProductionVirtualName -ProductionCluster $Cluster
    
    # 7. Need to run inquiry on each resource group
    foreach ($RG in $RGlist)
    {
        if ($RG -ne $RGlist[0]) { 
            write-host ", " -NoNewline
        }
    	write-host "$($RG.NetBiosName)" -NoNewLine
    
    	# 7.1 Inquiry is run in parallel and the event mechanism is used to signal completion of inquiry.
    	# 'DataSourceDetectionEvent' event signals the completion of inquiry. and the data sources obtained are added to the global variable
    	$joblist += register-objectevent -inputobject $RG -Eventname DatasourceDetectionEvent -Action {$global:DSlist += $($Event.SourceEventArgs.ProtectableObjects)}
    
    	# 7.2 Run inquiry
    	Get-DPMDatasource -ProductionServer $RG -Inquire -Async
    }
    write-host ")"
    
    # 8. Scan through each job created in the previous loop
    write-host "Inquiry listed"  -NoNewline
    $count = 0
    foreach ($job in $joblist)
    {
    	# 8.1 Waiting for the job to run
    	while ($job.State -eq "NotStarted")
    	{
            if ($global:DSlist.count -gt $count) {
                write-host $("." * ($global:DSlist.count - $count)) -noNewLine
                $count = $global:DSlist.count
            }
    		sleep 1
    	}
    }
    
    # 8.2 Inquiry complete on all resource groups
    
    write-host $global:DSlist.count "item(s)..."
    
    # 9. If object is a data source and of type Hyper-V and is currently not protected add to list of unprotected VMs
    $unprotectedDSList = @(($global:DSList) | where-object {$($_.Type.IsDatasource) -and ($($_.Type.Name) -match "Hyper-V") -and ! $($_.Protected) -and $($DoNotAdd -notcontains $($_.VMName))})
    
    # 10. Exit if there are no unprotected VMs
    if ($unprotectedDSList.count -lt 1) {
    	write-host "No new datasources found!"
    	exit 1
    }
    
    # 11. Obtain the target storage volume if specified and found.
    if ($DiskStorage -ne "") {
        $vols = Get-DPMDiskStorage -Volumes
        $targetstorage = $vols | ? {($_.Name -eq $DiskStorage)}
        if(!$targetstorage) {
            write-warning "Target storage volume not found! Using default..."
        } else {
            write-host "Selected $($targetstorage.Name)($($targetstorage.AccessPath)) as storage volume"
        }
    } else {
        write-host "No target storage volume specified. Using default..."
    }
    
    # 12. Obtain a modifiable protection group type
    $MPG = Get-DPMModifiableProtectionGroup $PG
    
    # 13. Perform the following for each new VM to add to protection
    foreach ($ds in $unprotectedDSList) {
    	write-host "Adding data source" $ds.Name "to" $MPG.FriendlyName
    	$npg = Add-DPMChildDatasource -ProtectionGroup $MPG -ChildDatasource $ds
    
    	# 13.1 Disk Allocation is skipped in case of short term protection being to tape.
    	if($MPG.protectionmethod -eq $tape) {continue;}
    
        # 13.2 Use target storage volume if specified and found.
        if(!$targetstorage) {
    	    Set-DPMDatasourceDiskAllocation -Datasource $ds -ProtectionGroup $MPG 
        }
        else {
            Set-DPMDatasourceDiskAllocation -Datasource $ds -ProtectionGroup $MPG -TargetStorage $targetstorage
        }
    }
    
    # 14 Note that this step will force immediate replica creation irrespective of the PG policy.
    Set-DPMReplicaCreationMethod -ProtectionGroup $MPG -Now
    
    write-host "Adding new Hyper-V data sources to" $MPG.FriendlyName
    
    # 15 Save the changes to the protection group. Replica creation will be triggered immediately.
    Set-DPMProtectionGroup $MPG
    
    write-warning "Disconnecting to DPM server: $dpmservername"
    $null = (Disconnect-DPMServer $dpmservername -erroraction silentlycontinue)
    write-host "Exiting from script"


    • Edited by RM de Jong Saturday, April 28, 2018 10:26 AM
    Saturday, April 28, 2018 10:25 AM