Skip to content

Instantly share code, notes, and snippets.

@MattHodge
Created September 16, 2017 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattHodge/f525d8a3a9d504a470f6c52cf3b8c9ca to your computer and use it in GitHub Desktop.
Save MattHodge/f525d8a3a9d504a470f6c52cf3b8c9ca to your computer and use it in GitHub Desktop.
ListVMsOnClusterForDPM.ps1
# Please Specify The FQDN or IP address of your DPM Server
$DPMServerName = "YOUR DPM SERVER"
# DSConfig.ps1
$infoText = "This script will generate the DatasourceGroups.xml file in the current path. Once this file is created merge it with the same file name under %programfiles%\Microsoft DPM\DPM\Config directory on the DPM server. Read the documentation for more details."
echo $infoText
$header = "<?xml version=`"1.0`" encoding=`"utf-16`"?> `n <DatasourceGroup xmlns:xsi=`"http://www.w3.org/2001/XMLSchema-instance`" xmlns:xsd=`"http://www.w3.org/2001/XMLSchema`" xmlns=`"http://schemas.microsoft.com/2003/dls/GroupDatasourceByDisk.xsd`">"
$footer = "</DatasourceGroup>"
import-module -name FailoverClusters
$dir = [guid]::NewGuid()
md $dir
$cluster = get-Cluster
$FQDN = $cluster.Name + "." + $cluster.Domain
$res = get-clusterresource | where-object { $_.ResourceType.Name -eq "Virtual Machine Configuration"}
foreach ($r in $res)
{
$VmObj = Get-ClusterParameter -inputobject $r | where {$_.Name -eq "VmStoreRootPath"} # Identifies the CSV volume on which the VM is hosted.
$VmName = Get-ClusterParameter -inputobject $r | where {$_.Name -eq "VmId"}
$vol = $vmobj.Value.Split("\")[2] # $vol will return to us the Volume<number> of the CSV on which the VM resides.
$line = "<Datasource DatasourceName=`"" + $VmName.Value +"`"" + " ProtectedServerName=`"" + $r.OwnerGroup.Name + "."+ $FQDN +"`"" + " WriterId=`"66841cd4-6ded-4f4b-8f17-fd23f8ddc3de`" />"
echo $line >> $dir\$vol # File VolumeX will contain entries for all VMs hosted on CSV VolumeX
}
echo $header > DataSourceGroups.xml
$filelist = dir $dir\Volume*
$GroupEndString = "</Group>"
foreach ($file in $filelist)
{
$GroupBeginString = "<Group GroupName=`"" + $file.Name + "-" + $FQDN + "`">" # Group name is kept VolumeX itself
echo $GroupBeginString >> DataSourceGroups.xml
type $file >> DataSourceGroups.xml # Consolidating groups pertaining to all the volumes.
echo $GroupEndString >> DataSourceGroups.xml
}
Remove-Item -Force -Recurse $dir
echo $footer >> DataSourceGroups.xml
# Copy The DataSourceGroups.xml file to the DPM Server
copy DataSourceGroups.xml \\$DPMServerName"\DPMConfig"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment