none
Powershell script to get size (Gb) of data sources RRS feed

  • Question

  • I got the below script online. I want to add a third column to give the size (Gb) of each data source named (recovery point volume or replica volume). Can anyone help by telling me the parameter to use for size please?

    get-dpmdatasource | where {$_.Protected -eq "True"} | select productionservername, name | Sort-Object productionservername, name 

    Tuesday, August 16, 2016 11:30 AM

Answers

  • hi, use parameter "DiskAllocation" or "ReplicaUsedSpace" (as a replica) and "ShadowCopyUsedSpace" (Recovery Point Volume)

    №1

    get-dpmdatasource | where {$_.Protected -eq "True"} | select productionservername, name, DiskAllocation | Sort-Object productionservername, name | fl

    №2

    $DPMServerName = "YOUR DPM SERVER NAME"
    
    
    $Info = @()
    
    Connect-DPMServer $DPMServerName 
    
    $pgList = Get-ProtectionGroup -DPMServerName $DPMServerName 
    if ($pgList -ne $null) 
    {
    foreach ($pg in $pgList) 
        {
    
    $dsList = Get-DPMDatasource -ProtectionGroup $pg | where {$_.Protected -eq "True"}
            foreach ($ds in $dsList) 
            {
            
            $currentReplicaUsedSpaceSizeInGb = [System.Math]::Round(($ds.ReplicaUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            $currentShadowCopyUsedSpaceSizeInGb = [System.Math]::Round(($ds.ShadowCopyUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            
            $objInfo = New-Object System.Object
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ProductionServerName' -Value $ds.ProductionServerName
            $objInfo | Add-Member -MemberType NoteProperty -Name 'Name' -Value $ds.Name
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ReplicaSizeInGb' -Value $currentReplicaUsedSpaceSizeInGb
            $objInfo | Add-Member -MemberType NoteProperty -Name 'recoveryPointVolumeSizeInGb' -Value $currentShadowCopyUsedSpaceSizeInGb 
    
            $Info += $objInfo
    
            
            }
            
        } # end foreach $pg
        
        
        
            
    } # end If $pglist
    
    $Info
    
    Disconnect-DPMServer $DPMServerName 


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Wednesday, August 17, 2016 1:18 PM
    Moderator
  • Thanks thats exactly what I wanted

    Do you know how I can pipe the results from number 2 into a file that can be opened by Excel please?

    I really appreciate your help

    try this :)

    Use PowerShell to Create CSV File to Open in Excel

    Introducing the PowerShell Excel Module

    Save Time By Using CSV Instead Of Excel With PowerShell

    Please, mark as answer if it's helped you!


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Thursday, August 18, 2016 2:21 PM
    Moderator
  • Thanks for that. I will spend some time going through it. 

    I know next to nothing about powershell

    Appreciate your time

    • Marked as answer by dpmoperator Friday, August 19, 2016 1:13 PM
    Thursday, August 18, 2016 4:47 PM
  • Thanks for that. I will spend some time going through it. 

    I know next to nothing about powershell

    Appreciate your time

    add some strings to script

     
    $OutputFilePath = "C:\temp\DPMUsedSpace"
    
    
    $Info | Select-Object ProductionServerName , Name, ReplicaSizeInGb, recoveryPointVolumeSizeInGb | Export-Csv -Path "$OutputFilePath.csv" -Encoding ascii -NoTypeInformation
    
    
    # load into Excel
    $excel = New-Object -ComObject Excel.Application 
    $excel.Visible = $true
    
    # change thread culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = 'en-US'
    
    $excel.Workbooks.Open("$OutputFilePath.csv").SaveAs("$OutputFilePath.xlsx",51)
    $excel.Quit()
    
    explorer.exe "/Select,$OutputFilePath.xlsx"
    

    Full script!

    $DPMServerName = "YOUR DPM Server Name"
    
    
    $Info = @()
    
    $OutputFilePath = "C:\temp\DPMUsedSpace"
    
    
    Connect-DPMServer $DPMServerName 
    
    $pgList = Get-ProtectionGroup -DPMServerName $DPMServerName 
    if ($pgList -ne $null) 
    {
    foreach ($pg in $pgList) 
        {
    
    $dsList = Get-DPMDatasource -ProtectionGroup $pg | where {$_.Protected -eq "True"}
            foreach ($ds in $dsList) 
            {
            
            $currentReplicaUsedSpaceSizeInGb = [System.Math]::Round(($ds.ReplicaUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            $currentShadowCopyUsedSpaceSizeInGb = [System.Math]::Round(($ds.ShadowCopyUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            
            $objInfo = New-Object System.Object
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ProductionServerName' -Value $ds.ProductionServerName
            $objInfo | Add-Member -MemberType NoteProperty -Name 'Name' -Value $ds.Name
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ReplicaSizeInGb' -Value $currentReplicaUsedSpaceSizeInGb
            $objInfo | Add-Member -MemberType NoteProperty -Name 'recoveryPointVolumeSizeInGb' -Value $currentShadowCopyUsedSpaceSizeInGb 
    
            $Info += $objInfo
    
            
            }
            
        } # end foreach $pg
        
        
        
            
    } # end If $pglist
    
    $Info | Select-Object ProductionServerName , Name, ReplicaSizeInGb, recoveryPointVolumeSizeInGb | Export-Csv -Path "$OutputFilePath.csv" -Encoding ascii -NoTypeInformation
    
    
    # load into Excel
    $excel = New-Object -ComObject Excel.Application 
    $excel.Visible = $true
    
    # change thread culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = 'en-US'
    
    $excel.Workbooks.Open("$OutputFilePath.csv").SaveAs("$OutputFilePath.xlsx",51)
    $excel.Quit()
    
    explorer.exe "/Select,$OutputFilePath.xlsx"
    
    Disconnect-DPMServer $DPMServerName 

    dpmoperator, Be happy!


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Monday, August 22, 2016 8:22 AM
    Moderator
  • Thanks so much. You are very generous with your time! Now I have exactly what I want.

    • Marked as answer by dpmoperator Tuesday, August 23, 2016 9:45 AM
    Tuesday, August 23, 2016 9:41 AM

All replies

  • hi, use parameter "DiskAllocation" or "ReplicaUsedSpace" (as a replica) and "ShadowCopyUsedSpace" (Recovery Point Volume)

    №1

    get-dpmdatasource | where {$_.Protected -eq "True"} | select productionservername, name, DiskAllocation | Sort-Object productionservername, name | fl

    №2

    $DPMServerName = "YOUR DPM SERVER NAME"
    
    
    $Info = @()
    
    Connect-DPMServer $DPMServerName 
    
    $pgList = Get-ProtectionGroup -DPMServerName $DPMServerName 
    if ($pgList -ne $null) 
    {
    foreach ($pg in $pgList) 
        {
    
    $dsList = Get-DPMDatasource -ProtectionGroup $pg | where {$_.Protected -eq "True"}
            foreach ($ds in $dsList) 
            {
            
            $currentReplicaUsedSpaceSizeInGb = [System.Math]::Round(($ds.ReplicaUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            $currentShadowCopyUsedSpaceSizeInGb = [System.Math]::Round(($ds.ShadowCopyUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            
            $objInfo = New-Object System.Object
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ProductionServerName' -Value $ds.ProductionServerName
            $objInfo | Add-Member -MemberType NoteProperty -Name 'Name' -Value $ds.Name
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ReplicaSizeInGb' -Value $currentReplicaUsedSpaceSizeInGb
            $objInfo | Add-Member -MemberType NoteProperty -Name 'recoveryPointVolumeSizeInGb' -Value $currentShadowCopyUsedSpaceSizeInGb 
    
            $Info += $objInfo
    
            
            }
            
        } # end foreach $pg
        
        
        
            
    } # end If $pglist
    
    $Info
    
    Disconnect-DPMServer $DPMServerName 


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Wednesday, August 17, 2016 1:18 PM
    Moderator
  • Thanks thats exactly what I wanted

    Do you know how I can pipe the results from number 2 into a file that can be opened by Excel please?

    I really appreciate your help

    Wednesday, August 17, 2016 4:42 PM
  • Thanks thats exactly what I wanted

    Do you know how I can pipe the results from number 2 into a file that can be opened by Excel please?

    I really appreciate your help

    try this :)

    Use PowerShell to Create CSV File to Open in Excel

    Introducing the PowerShell Excel Module

    Save Time By Using CSV Instead Of Excel With PowerShell

    Please, mark as answer if it's helped you!


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Thursday, August 18, 2016 2:21 PM
    Moderator
  • Thanks for that. I will spend some time going through it. 

    I know next to nothing about powershell

    Appreciate your time

    • Marked as answer by dpmoperator Friday, August 19, 2016 1:13 PM
    Thursday, August 18, 2016 4:47 PM
  • Thanks for that. I will spend some time going through it. 

    I know next to nothing about powershell

    Appreciate your time

    add some strings to script

     
    $OutputFilePath = "C:\temp\DPMUsedSpace"
    
    
    $Info | Select-Object ProductionServerName , Name, ReplicaSizeInGb, recoveryPointVolumeSizeInGb | Export-Csv -Path "$OutputFilePath.csv" -Encoding ascii -NoTypeInformation
    
    
    # load into Excel
    $excel = New-Object -ComObject Excel.Application 
    $excel.Visible = $true
    
    # change thread culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = 'en-US'
    
    $excel.Workbooks.Open("$OutputFilePath.csv").SaveAs("$OutputFilePath.xlsx",51)
    $excel.Quit()
    
    explorer.exe "/Select,$OutputFilePath.xlsx"
    

    Full script!

    $DPMServerName = "YOUR DPM Server Name"
    
    
    $Info = @()
    
    $OutputFilePath = "C:\temp\DPMUsedSpace"
    
    
    Connect-DPMServer $DPMServerName 
    
    $pgList = Get-ProtectionGroup -DPMServerName $DPMServerName 
    if ($pgList -ne $null) 
    {
    foreach ($pg in $pgList) 
        {
    
    $dsList = Get-DPMDatasource -ProtectionGroup $pg | where {$_.Protected -eq "True"}
            foreach ($ds in $dsList) 
            {
            
            $currentReplicaUsedSpaceSizeInGb = [System.Math]::Round(($ds.ReplicaUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            $currentShadowCopyUsedSpaceSizeInGb = [System.Math]::Round(($ds.ShadowCopyUsedSpace * 1.0) / (1024.0 * 1024.0 * 1024.0), 2);
            
            $objInfo = New-Object System.Object
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ProductionServerName' -Value $ds.ProductionServerName
            $objInfo | Add-Member -MemberType NoteProperty -Name 'Name' -Value $ds.Name
            $objInfo | Add-Member -MemberType NoteProperty -Name 'ReplicaSizeInGb' -Value $currentReplicaUsedSpaceSizeInGb
            $objInfo | Add-Member -MemberType NoteProperty -Name 'recoveryPointVolumeSizeInGb' -Value $currentShadowCopyUsedSpaceSizeInGb 
    
            $Info += $objInfo
    
            
            }
            
        } # end foreach $pg
        
        
        
            
    } # end If $pglist
    
    $Info | Select-Object ProductionServerName , Name, ReplicaSizeInGb, recoveryPointVolumeSizeInGb | Export-Csv -Path "$OutputFilePath.csv" -Encoding ascii -NoTypeInformation
    
    
    # load into Excel
    $excel = New-Object -ComObject Excel.Application 
    $excel.Visible = $true
    
    # change thread culture
    [System.Threading.Thread]::CurrentThread.CurrentCulture = 'en-US'
    
    $excel.Workbooks.Open("$OutputFilePath.csv").SaveAs("$OutputFilePath.xlsx",51)
    $excel.Quit()
    
    explorer.exe "/Select,$OutputFilePath.xlsx"
    
    Disconnect-DPMServer $DPMServerName 

    dpmoperator, Be happy!


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Monday, August 22, 2016 8:22 AM
    Moderator
  • Thanks so much. You are very generous with your time! Now I have exactly what I want.

    • Marked as answer by dpmoperator Tuesday, August 23, 2016 9:45 AM
    Tuesday, August 23, 2016 9:41 AM
  • You are welcome! :)

    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Tuesday, August 23, 2016 12:37 PM
    Moderator