none
purge disk pool RRS feed

  • Question

  • How can I purge old or unwanted replicas from the Disk Storage Pool?

    I had trouble with a Protection Group where I could not send it to Tape using BackupToTape.ps1 and when I tried to modify the PG it would error.

    To fix this I deleted the PG and kept recovery points (for safety), but now that I have successfully remade the PG and backed up, I want to purge the old data from the Storage pool.

    I am guessing that I could delete it from within DiskManager, but is there a cleaner, easier way?

    Wednesday, July 31, 2013 3:40 AM

Answers

  • Hi,

    It's possible they will be retained until all the recovery points expire based on retention range.

    1) Get a list of all the volume guids on the DPM Server,  from an administrative command prompt:

    c:\>mountvol | find /i "\\?\">MOUNTVOL.TXT

    2) Save the following as Migrate_disk_Space_Needed.ps1       

    3) Start a DPM power shell and run the script with the verbose parameter.

        Migrate_disk_Space_Needed.ps1 verbose                                

    4)  The volume GUIDS in use by DPM will be in the output.  Compare those guids with the mountvol.txt. With the exception of the Local disks like C: - you can delete the volume with GUIDS not in use by DPM.   You can use mountvol to assign drive letters, then delete them from disk management. 

    ###########################################################################################
    #                                                                                              
    # This script will check how much space is needed to migrate an entire disk to a new one(s)    
    #                                                                                                                       
    # Date Created  : 12/15/2011                                                                   
    # Last modified : 05/28/2013
    #                                                                                              
    # Change log                                                                                   
    # ==========                                                                                   
    #             
    #       2.1 - Number of non-colocated data sources that can still be added was always returning 0
    #       2.0 - Added LDMAndShrinkStats to this script.
    #             http://blogs.technet.com/b/dpm/archive/2010/03/30/what-volume-to-migrate-first.aspx
    #       1.3 - Added total space used by datasource which is handy when there are so many
    #             extended volumes...                                                                                 
    #             Now we generate output to a file
    #       1.2 - Updated Script to deal with Colocated datasources                            
    #       1.1 - Minor updates                                                                
    #                                                                                              
    # This version of the script was only tested on DPM 2010/2012   
    #   
    #  Migrate_disk_Space_Needed.ps1 verbose                                 
    #                                                                                              
    ###########################################################################################
    
    param ([string] $global:verbose)
      $Version      = 2.1
      $ScriptName   = "MigrateSpaceNeeded"
    
    function GetMigSizeByDisk
    { 
    	param($disk, $extents, $dss, $Vols ) 
    	[int64]$size = 0 
    	#For all data source members on current disk 
        $disk_distinct = $disk.pgmember | sort-object volumesetid -Unique  
    	foreach ($m in $disk_distinct) 
    	{ 
    		#we use ds to take sizes from rather than selects and sum proper extents 
    		$ds = $dss | ? {$m.DatasourceId -eq $_.id}
            if ($verbose.toupper() -eq 'VERBOSE')
            {
        		write-host; write-host $ds -foreground red 
                $ds.ProtectableObjectLoadPath.Keys | out-file $outfile -Encoding ascii -Append
    
            }
            $RecoVolume = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 2 })        
            $RecoExpr = "Guidname='{0}'" -f $RecoVolume[0].GuidName 
    
            $RecoExtents = @($extents | ? { $_.guidname -eq $RecoVolume[0].guidname })
    		# At least 1 recovery point volume extent lives on same disk as replica 
    		# We must now add shadowcopy size to total 
    		$size += $ds.ReplicaSize + $ds.ShadowCopyAreaSize #$includes all extents whereever they are   
            $DatasourceVolumeSize = $ds.ReplicaSize + $ds.ShadowCopyAreaSize #$includes all extents whereever they are   
            $replica = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 1 })
    		$expr = "guidname= '{0}'"  -f $replica[0].guidname
            $replica2 = $extents | ? { $_.guidname -eq $replica[0].Guidname }
            if ($verbose.toupper() -eq 'VERBOSE')
            {
    		  foreach ($replica1 in $replica2)
    		  {
    		      write-host "   Replica volume Size  - $('{0,8:N2}'-f($replica1.extentsize/$GB)) GB - Replica on Disk $('{0,3}'-f($replica1.ntdisknumber)) - Volume GUID " $replica1.Guidname -foreground green 
                  "   Replica volume Size  - $('{0,8:N2}'-f($replica1.extentsize/$GB)) GB - Replica on Disk $('{0,3}'-f($replica1.ntdisknumber)) - Volume GUID " + $replica1.Guidname | out-file $outfile -Encoding ascii -Append
    
    		  }
            }
    		$expr = "VolumeSetId='{0}' and usage = 2" -f $m.VolumeSetID, $vols.usage
            $Recovery = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 2 })
            $recovery2 = $extents | ? { $_.guidname -eq $recovery[0].Guidname }
            if ($verbose.toupper() -eq 'VERBOSE')
            {
    		  foreach ($recovery1 in $recovery2)
    		  {
    		      write-host "   Recovery volume size - $('{0,8:N2}' -f($recovery1.Extentsize/$GB)) GB - Recovey on Disk $('{0,3}' -f($recovery1.ntdisknumber)) - Volume GUID " $recovery1.Guidname -foreground green
                  "   Recovery volume size - $('{0,8:N2}' -f($recovery1.Extentsize/$GB)) GB - Recovey on Disk $('{0,3}' -f($recovery1.ntdisknumber)) - Volume GUID " + $recovery1.Guidname | out-file $outfile -Encoding ascii -Append
    		  }
              write-host "   Total Volumes size   - $('{0,8:N2}' -f($DatasourceVolumeSize/$GB)) GB"
              "   Total Volumes size   - $('{0,8:N2}' -f($DatasourceVolumeSize/$GB)) GB" | out-file $outfile -Encoding ascii -Append
              " " | out-file $outfile -Encoding ascii -Append
            }        
    	}    
        
    	return $size
    } 
    
    
    $ErrorActionPreference = "silentlycontinue"
    Add-PSSnapin -Name Microsoft.DataProtectionManager.PowerShell
    add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue
    $ConfirmPreference = 'None'
    
    $global:MB = 1024 * 1024 
    $global:GB = $MB * 1024 
    $global:dpmservername = @(hostname) 
    $ConfirmPreference = 'None'
    $outfile = $ScriptName + ".txt"
    out-file $outfile -Encoding ascii
    
    #get sqlserver and instance
    $DPMServerConnection = (Connect-DPMServer (&hostname))
    $DPMServername = $DPMServerConnection.name
    $DB = $dpmserverconnection.dpmdatabaselogicalpath.substring($dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\') + 1,$dpmserverconnection.DPMDatabaseLogicalPath.Length - $dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\') -1 )
    $servername   = $dpmserverconnection.dpmdatabaselogicalpath.substring(0,$dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\'))
    
    $VolTable = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select *  from tbl_SPM_Volume where VolumeSetID is not null'
    
    $extentlist = Invoke-Sqlcmd -ServerInstance $servername -Database $db -Query 'select extent.diskid, extent.DiskOffset, extent.GuidName, extent.ExtentSize,disk.NTDiskNumber  from tbl_SPM_Extent extent join tbl_SPM_Disk disk on extent.DiskID = disk.DiskID'
    
    
    $disks = @(Get-DPMDisk $dpmservername  | ? { $_.IsInStoragePool -eq $true}  |  sort -Property NtDiskId )
    $datasourcelist = Get-Datasource $dpmservername
    
    #Now go to work
    cls 
    write-host "$ScriptName Version $version`nFor datasource details, run with verbose switch`nExample: <script_name> verbose"  -f white
    
    Write-Host ("`nEvaluating {0} DPM disk(s)...`n" -f $disks.count) -ForegroundColor yellow 
    foreach ($d in $disks) 
    { 
    	$MigSize = ( (GetMigSizeByDisk $d $extentlist $datasourcelist $Voltable)/ $GB).Tostring("N2") 
    	Write-Host (" ==> to migrate Disk-{0} you will need $MigSize GB on the destination" -f $d.NtDiskID) -ForegroundColor cyan 
        " ==> to migrate Disk-{0} you will need $MigSize GB on the destination`n" -f $d.NtDiskID | out-file $outfile -Encoding ascii -Append
        " "                                                                      | out-file $outfile -Encoding ascii -Append
    } 
    
    # Based on LDMAndShrinkStats version = "1.6" 
    $ExtentCount = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select count(*) as  TotalNumberOfDynamicExtents from tbl_SPM_Extent extent where extent.DiskID in (select DiskID from tbl_SPM_Disk where DiskType = 1)' 
    $DSCount     = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select COUNT(*) as TotalNumberOfDatasources from tbl_IM_Datasource where ProtectedGroupId is not null' 
    $volcount    = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select COUNT(*) as NumberOfVolumes from tbl_SPM_Volume where VolumeSetID is not null'
    
    $dpmRemaining = [math]::truncate(600 - $volcount.numberofvolumes) 
    $diskcount = $disks.count 
    
    Write-Host "Total disks in DPM Storage Pool".PadRight(31)  ":" $diskcount
    Write-Host "Total volumes".PadRight(31) ":" $volcount.NumberOfVolumes
    Write-Host "Total extents".PadRight(31) ":" $ExtentCount.TotalNumberOfDynamicExtents
    Write-Host "Total data sources".PadRight(31) ":" $DSCount.TotalNumberOfDatasources
    $usedslots = 1 + $diskcount + (2*$volcount) + $ExtentCount 
    $slotsRemaining = 2960-$usedslots 
    $volRemaining = [math]::Truncate($slotsRemaining/3) 
    if ($dpmRemaining -lt $volRemaining) {$dsRemaining = [math]::Truncate($dpmRemaining/2)} 
    else {$dsRemaining = [math]::Truncate($volRemaining/2)} 
    Write-Host "Number of non-colocated data sources that can still be added:" $dsRemaining
    Write-Host "`nData source extent list..." 
    
    "Total disks in DPM Storage Pool".PadRight(31) +  ": " + $diskcount            | out-file $outfile -Encoding ascii -Append
    "Total volumes".PadRight(31) + ": " + $volcount.NumberOfVolumes                | out-file $outfile -Encoding ascii -Append
    "Total extents".PadRight(31) + ": " + $ExtentCount.TotalNumberOfDynamicExtents | out-file $outfile -Encoding ascii -Append
    "Total data sources".PadRight(31) + ": " + $DSCount.TotalNumberOfDatasources   | out-file $outfile -Encoding ascii -Append
    "Number of non-colocated data sources that can still be added: "+ $dsRemaining | out-file $outfile -Encoding ascii -Append
    " "                                                                            | out-file $outfile -Encoding ascii -Append
    "Data source extent list..."                                                   | out-file $outfile -Encoding ascii -Append
    " "                                                                            | out-file $outfile -Encoding ascii -Append
    
    $DSwithExtentsTable = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'SELECT (select DataSourceName from tbl_IM_Datasource ds2 where DataSourceId = DS.DataSourceId) as DatasourceName, 
    (select pg.FriendlyName from tbl_IM_Datasource ds2 join tbl_IM_ProtectedGroup pg on ds2.ProtectedGroupId = pg.ProtectedGroupId 
    where DataSourceId = DS.DataSourceId) as ProtectionGroupName, 
    COUNT(Extent.DiskID) as NumberOfExtents, replica.PhysicalReplicaId as PhysicalReplicaId, DS.DatasourceId as DatasourceId 
    FROM tbl_SPM_Extent Extent WITH (NOLOCK)  
        JOIN dbo.tbl_SPM_Volume Volume WITH (NOLOCK)  
            ON Extent.GuidName = Volume.GuidName  
        JOIN dbo.tbl_PRM_LogicalReplica Replica WITH (NOLOCK)  
            ON Replica.PhysicalReplicaId = Volume.VolumeSetID  
        JOIN dbo.tbl_IM_Datasource DS WITH (NOLOCK)  
            ON Replica.DataSourceId = DS.DataSourceId 
    GROUP BY DS.DataSourceId, Replica.PhysicalReplicaId 
    Order by NumberOfExtents desc'
    $DSwithExtentsRows =   $DSwithExtentsTable
    $physicalReplicasPrinted = @{} 
    foreach ($row in $DSwithExtentsRows) 
    {  
        if ($physicalReplicasPrinted.Contains($row["PhysicalReplicaId"])) {  
            $row.Delete()  
        } else {  
            $physicalReplicasPrinted[$row["PhysicalReplicaId"]] = 1;  
        } 
    } 
    $DSwithExtentsTable.AcceptChanges() 
    $DSwithExtentsRows | ft –AutoSize 
    $DSwithExtentsRows | ft -AutoSize | out-file $outfile -Encoding ascii -Append
    Write-Host "`nReplica colocation counts..." 
    $PhysReplCount = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select physicalreplicaid as PhysicalReplicaId, COUNT(*) as Count from tbl_PRM_LogicalReplica where physicalreplicaid is not null and datasourceid is not null group by PhysicalReplicaId'
    $PhysReplCount | ft –AutoSize 
    $PhysReplCount | ft –AutoSize | out-file $outfile -Encoding ascii -Append
    Write-Host "`nLDM alerts list..." 
    $LDMAlerts =   $db.ExecuteWithResults($LDMAlertsCmd).Tables[0].rows 
    if ($LDMAlerts.Count -gt 0 ) {  
        $LDMAlerts | ft –AutoSize 
        $LDMAlerts | ft -AutoSize | out-file $outfile -Encoding ascii -Append
    } 
    else {write-host "None found!" -f white} 
    Write-Host "`nDone!" 
    #--------------------------------- 
    
     notepad $outfile


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.


    Thursday, August 1, 2013 12:33 AM
    Moderator

All replies

  • Hi,

    When you removed the PG and selected to retain replica, that moved the data sources and associated volumes into an inactive protection group.

    depending on the data source type and if colocation was enabled, when you reprotected them dpm either reused the original volumes and removed them from inactive protection, or it made new volumes and the original are still in inactive protection group.  If the latter, you can simply delete them from inactive protection. If you don't see any inactive protection group, then dpm reused the volumes and there is nothing to delete.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, July 31, 2013 4:02 AM
    Moderator
  • Hi Mike

    That is what I was hoping, but they are not in inactive protection. DPM seemed to create new volumes when I recreated the PG. I think the fact that The disk pool now has very little free space left confirms this.  How can I now recover the disk pool space? 

    Wednesday, July 31, 2013 10:40 PM
  • Hi,

    It's possible they will be retained until all the recovery points expire based on retention range.

    1) Get a list of all the volume guids on the DPM Server,  from an administrative command prompt:

    c:\>mountvol | find /i "\\?\">MOUNTVOL.TXT

    2) Save the following as Migrate_disk_Space_Needed.ps1       

    3) Start a DPM power shell and run the script with the verbose parameter.

        Migrate_disk_Space_Needed.ps1 verbose                                

    4)  The volume GUIDS in use by DPM will be in the output.  Compare those guids with the mountvol.txt. With the exception of the Local disks like C: - you can delete the volume with GUIDS not in use by DPM.   You can use mountvol to assign drive letters, then delete them from disk management. 

    ###########################################################################################
    #                                                                                              
    # This script will check how much space is needed to migrate an entire disk to a new one(s)    
    #                                                                                                                       
    # Date Created  : 12/15/2011                                                                   
    # Last modified : 05/28/2013
    #                                                                                              
    # Change log                                                                                   
    # ==========                                                                                   
    #             
    #       2.1 - Number of non-colocated data sources that can still be added was always returning 0
    #       2.0 - Added LDMAndShrinkStats to this script.
    #             http://blogs.technet.com/b/dpm/archive/2010/03/30/what-volume-to-migrate-first.aspx
    #       1.3 - Added total space used by datasource which is handy when there are so many
    #             extended volumes...                                                                                 
    #             Now we generate output to a file
    #       1.2 - Updated Script to deal with Colocated datasources                            
    #       1.1 - Minor updates                                                                
    #                                                                                              
    # This version of the script was only tested on DPM 2010/2012   
    #   
    #  Migrate_disk_Space_Needed.ps1 verbose                                 
    #                                                                                              
    ###########################################################################################
    
    param ([string] $global:verbose)
      $Version      = 2.1
      $ScriptName   = "MigrateSpaceNeeded"
    
    function GetMigSizeByDisk
    { 
    	param($disk, $extents, $dss, $Vols ) 
    	[int64]$size = 0 
    	#For all data source members on current disk 
        $disk_distinct = $disk.pgmember | sort-object volumesetid -Unique  
    	foreach ($m in $disk_distinct) 
    	{ 
    		#we use ds to take sizes from rather than selects and sum proper extents 
    		$ds = $dss | ? {$m.DatasourceId -eq $_.id}
            if ($verbose.toupper() -eq 'VERBOSE')
            {
        		write-host; write-host $ds -foreground red 
                $ds.ProtectableObjectLoadPath.Keys | out-file $outfile -Encoding ascii -Append
    
            }
            $RecoVolume = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 2 })        
            $RecoExpr = "Guidname='{0}'" -f $RecoVolume[0].GuidName 
    
            $RecoExtents = @($extents | ? { $_.guidname -eq $RecoVolume[0].guidname })
    		# At least 1 recovery point volume extent lives on same disk as replica 
    		# We must now add shadowcopy size to total 
    		$size += $ds.ReplicaSize + $ds.ShadowCopyAreaSize #$includes all extents whereever they are   
            $DatasourceVolumeSize = $ds.ReplicaSize + $ds.ShadowCopyAreaSize #$includes all extents whereever they are   
            $replica = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 1 })
    		$expr = "guidname= '{0}'"  -f $replica[0].guidname
            $replica2 = $extents | ? { $_.guidname -eq $replica[0].Guidname }
            if ($verbose.toupper() -eq 'VERBOSE')
            {
    		  foreach ($replica1 in $replica2)
    		  {
    		      write-host "   Replica volume Size  - $('{0,8:N2}'-f($replica1.extentsize/$GB)) GB - Replica on Disk $('{0,3}'-f($replica1.ntdisknumber)) - Volume GUID " $replica1.Guidname -foreground green 
                  "   Replica volume Size  - $('{0,8:N2}'-f($replica1.extentsize/$GB)) GB - Replica on Disk $('{0,3}'-f($replica1.ntdisknumber)) - Volume GUID " + $replica1.Guidname | out-file $outfile -Encoding ascii -Append
    
    		  }
            }
    		$expr = "VolumeSetId='{0}' and usage = 2" -f $m.VolumeSetID, $vols.usage
            $Recovery = @($Vols | ? { $_.volumesetid -eq $m.VolumeSetId.Guid -and  $_.usage -eq 2 })
            $recovery2 = $extents | ? { $_.guidname -eq $recovery[0].Guidname }
            if ($verbose.toupper() -eq 'VERBOSE')
            {
    		  foreach ($recovery1 in $recovery2)
    		  {
    		      write-host "   Recovery volume size - $('{0,8:N2}' -f($recovery1.Extentsize/$GB)) GB - Recovey on Disk $('{0,3}' -f($recovery1.ntdisknumber)) - Volume GUID " $recovery1.Guidname -foreground green
                  "   Recovery volume size - $('{0,8:N2}' -f($recovery1.Extentsize/$GB)) GB - Recovey on Disk $('{0,3}' -f($recovery1.ntdisknumber)) - Volume GUID " + $recovery1.Guidname | out-file $outfile -Encoding ascii -Append
    		  }
              write-host "   Total Volumes size   - $('{0,8:N2}' -f($DatasourceVolumeSize/$GB)) GB"
              "   Total Volumes size   - $('{0,8:N2}' -f($DatasourceVolumeSize/$GB)) GB" | out-file $outfile -Encoding ascii -Append
              " " | out-file $outfile -Encoding ascii -Append
            }        
    	}    
        
    	return $size
    } 
    
    
    $ErrorActionPreference = "silentlycontinue"
    Add-PSSnapin -Name Microsoft.DataProtectionManager.PowerShell
    add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue
    $ConfirmPreference = 'None'
    
    $global:MB = 1024 * 1024 
    $global:GB = $MB * 1024 
    $global:dpmservername = @(hostname) 
    $ConfirmPreference = 'None'
    $outfile = $ScriptName + ".txt"
    out-file $outfile -Encoding ascii
    
    #get sqlserver and instance
    $DPMServerConnection = (Connect-DPMServer (&hostname))
    $DPMServername = $DPMServerConnection.name
    $DB = $dpmserverconnection.dpmdatabaselogicalpath.substring($dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\') + 1,$dpmserverconnection.DPMDatabaseLogicalPath.Length - $dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\') -1 )
    $servername   = $dpmserverconnection.dpmdatabaselogicalpath.substring(0,$dpmserverconnection.DPMDatabaseLogicalPath.LastIndexOf('\'))
    
    $VolTable = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select *  from tbl_SPM_Volume where VolumeSetID is not null'
    
    $extentlist = Invoke-Sqlcmd -ServerInstance $servername -Database $db -Query 'select extent.diskid, extent.DiskOffset, extent.GuidName, extent.ExtentSize,disk.NTDiskNumber  from tbl_SPM_Extent extent join tbl_SPM_Disk disk on extent.DiskID = disk.DiskID'
    
    
    $disks = @(Get-DPMDisk $dpmservername  | ? { $_.IsInStoragePool -eq $true}  |  sort -Property NtDiskId )
    $datasourcelist = Get-Datasource $dpmservername
    
    #Now go to work
    cls 
    write-host "$ScriptName Version $version`nFor datasource details, run with verbose switch`nExample: <script_name> verbose"  -f white
    
    Write-Host ("`nEvaluating {0} DPM disk(s)...`n" -f $disks.count) -ForegroundColor yellow 
    foreach ($d in $disks) 
    { 
    	$MigSize = ( (GetMigSizeByDisk $d $extentlist $datasourcelist $Voltable)/ $GB).Tostring("N2") 
    	Write-Host (" ==> to migrate Disk-{0} you will need $MigSize GB on the destination" -f $d.NtDiskID) -ForegroundColor cyan 
        " ==> to migrate Disk-{0} you will need $MigSize GB on the destination`n" -f $d.NtDiskID | out-file $outfile -Encoding ascii -Append
        " "                                                                      | out-file $outfile -Encoding ascii -Append
    } 
    
    # Based on LDMAndShrinkStats version = "1.6" 
    $ExtentCount = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select count(*) as  TotalNumberOfDynamicExtents from tbl_SPM_Extent extent where extent.DiskID in (select DiskID from tbl_SPM_Disk where DiskType = 1)' 
    $DSCount     = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select COUNT(*) as TotalNumberOfDatasources from tbl_IM_Datasource where ProtectedGroupId is not null' 
    $volcount    = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select COUNT(*) as NumberOfVolumes from tbl_SPM_Volume where VolumeSetID is not null'
    
    $dpmRemaining = [math]::truncate(600 - $volcount.numberofvolumes) 
    $diskcount = $disks.count 
    
    Write-Host "Total disks in DPM Storage Pool".PadRight(31)  ":" $diskcount
    Write-Host "Total volumes".PadRight(31) ":" $volcount.NumberOfVolumes
    Write-Host "Total extents".PadRight(31) ":" $ExtentCount.TotalNumberOfDynamicExtents
    Write-Host "Total data sources".PadRight(31) ":" $DSCount.TotalNumberOfDatasources
    $usedslots = 1 + $diskcount + (2*$volcount) + $ExtentCount 
    $slotsRemaining = 2960-$usedslots 
    $volRemaining = [math]::Truncate($slotsRemaining/3) 
    if ($dpmRemaining -lt $volRemaining) {$dsRemaining = [math]::Truncate($dpmRemaining/2)} 
    else {$dsRemaining = [math]::Truncate($volRemaining/2)} 
    Write-Host "Number of non-colocated data sources that can still be added:" $dsRemaining
    Write-Host "`nData source extent list..." 
    
    "Total disks in DPM Storage Pool".PadRight(31) +  ": " + $diskcount            | out-file $outfile -Encoding ascii -Append
    "Total volumes".PadRight(31) + ": " + $volcount.NumberOfVolumes                | out-file $outfile -Encoding ascii -Append
    "Total extents".PadRight(31) + ": " + $ExtentCount.TotalNumberOfDynamicExtents | out-file $outfile -Encoding ascii -Append
    "Total data sources".PadRight(31) + ": " + $DSCount.TotalNumberOfDatasources   | out-file $outfile -Encoding ascii -Append
    "Number of non-colocated data sources that can still be added: "+ $dsRemaining | out-file $outfile -Encoding ascii -Append
    " "                                                                            | out-file $outfile -Encoding ascii -Append
    "Data source extent list..."                                                   | out-file $outfile -Encoding ascii -Append
    " "                                                                            | out-file $outfile -Encoding ascii -Append
    
    $DSwithExtentsTable = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'SELECT (select DataSourceName from tbl_IM_Datasource ds2 where DataSourceId = DS.DataSourceId) as DatasourceName, 
    (select pg.FriendlyName from tbl_IM_Datasource ds2 join tbl_IM_ProtectedGroup pg on ds2.ProtectedGroupId = pg.ProtectedGroupId 
    where DataSourceId = DS.DataSourceId) as ProtectionGroupName, 
    COUNT(Extent.DiskID) as NumberOfExtents, replica.PhysicalReplicaId as PhysicalReplicaId, DS.DatasourceId as DatasourceId 
    FROM tbl_SPM_Extent Extent WITH (NOLOCK)  
        JOIN dbo.tbl_SPM_Volume Volume WITH (NOLOCK)  
            ON Extent.GuidName = Volume.GuidName  
        JOIN dbo.tbl_PRM_LogicalReplica Replica WITH (NOLOCK)  
            ON Replica.PhysicalReplicaId = Volume.VolumeSetID  
        JOIN dbo.tbl_IM_Datasource DS WITH (NOLOCK)  
            ON Replica.DataSourceId = DS.DataSourceId 
    GROUP BY DS.DataSourceId, Replica.PhysicalReplicaId 
    Order by NumberOfExtents desc'
    $DSwithExtentsRows =   $DSwithExtentsTable
    $physicalReplicasPrinted = @{} 
    foreach ($row in $DSwithExtentsRows) 
    {  
        if ($physicalReplicasPrinted.Contains($row["PhysicalReplicaId"])) {  
            $row.Delete()  
        } else {  
            $physicalReplicasPrinted[$row["PhysicalReplicaId"]] = 1;  
        } 
    } 
    $DSwithExtentsTable.AcceptChanges() 
    $DSwithExtentsRows | ft –AutoSize 
    $DSwithExtentsRows | ft -AutoSize | out-file $outfile -Encoding ascii -Append
    Write-Host "`nReplica colocation counts..." 
    $PhysReplCount = Invoke-Sqlcmd -ServerInstance $servername -Database $DB -Query 'select physicalreplicaid as PhysicalReplicaId, COUNT(*) as Count from tbl_PRM_LogicalReplica where physicalreplicaid is not null and datasourceid is not null group by PhysicalReplicaId'
    $PhysReplCount | ft –AutoSize 
    $PhysReplCount | ft –AutoSize | out-file $outfile -Encoding ascii -Append
    Write-Host "`nLDM alerts list..." 
    $LDMAlerts =   $db.ExecuteWithResults($LDMAlertsCmd).Tables[0].rows 
    if ($LDMAlerts.Count -gt 0 ) {  
        $LDMAlerts | ft –AutoSize 
        $LDMAlerts | ft -AutoSize | out-file $outfile -Encoding ascii -Append
    } 
    else {write-host "None found!" -f white} 
    Write-Host "`nDone!" 
    #--------------------------------- 
    
     notepad $outfile


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.


    Thursday, August 1, 2013 12:33 AM
    Moderator