Created
September 16, 2017 21:58
-
-
Save MattHodge/f525d8a3a9d504a470f6c52cf3b8c9ca to your computer and use it in GitHub Desktop.
ListVMsOnClusterForDPM.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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