Latest version V1.2 of the script.
#Resized Replica Volume on Modern Backup Storage
#Tested on DPM 2016 + UR2 on Windows 2016.
# V1.1 - added error checking when defragsvc is disabled
# V1.2 - Only include PG's with short term disk is true IsDiskShortTerm = 1 + show size in MB
$version="V1.2"
$ErrorActionPreference = "silentlycontinue"
[uint64] $GB=1024*1024*1024
$logfile="ResizeReplica.LOG"
$confirmpreference = "None"
function Show_help
{
cls
write-host "Version: $version" -foregroundcolor cyan
write-host "A: User Selects data source to resize replica" -foregroundcolor green
write-host "B: User enters new Replica Size in GB" -foregroundcolor green
write-host "Appending to log file $logfile`n" -foregroundcolor white
write-host "User Accepts all responsibilities by entering a data source or just pressing [Enter] " -foregroundcolor white -backgroundcolor blue
}
"" >>$logfile
"**********************************" >> $logfile
"Version $version" >> $logfile
get-date >> $logfile
show_help
$DPM = Connect-dpmserver -Dpmservername (&hostname)
$DPMservername = (&hostname)
"Selected DPM server = $DPMservername" >> $logfile
write-host "`nRetrieving list of data sources on $Dpmservername`n" -foregroundcolor green
$pglist = @(Get-ProtectionGroup |where { $_.IsDiskShortTerm -eq 1}) # Created PGlist as array in case we have a single protection group.
$ds=@()
$count = 0
$dscount = 0
foreach ($count in 0..($pglist.count - 1))
{
#write-host $pglist[$count].friendlyname
$ds += @(get-datasource $pglist[$count]) # Created DS as array in case we have a single protection group.
#write-host $ds
#write-host $count -foreground yellow
}
if ( Get-Datasource $DPMservername -inactive) {$ds += Get-Datasource $DPMservername -inactive |where {$_.IsDiskInactive -eq 1}} #Include Inactive DataSources with Disk Protection
$i=0
write-host "Index Protection Group Computer Path Replica-Size-MBytes"
write-host "------------------------------------------------------------------------------------------------------"
foreach ($l in $ds)
{
"[{0,3}] {1,-20} {2,-20} {3,-35} {4}" -f $i, $l.ProtectionGroupName, $l.psinfo.netbiosname, $l.logicalpath, ($l.replicasize/1024/1024)
$i++
}
$DSname=read-host "`nEnter a data source index number from the list above."
if (!$DSname)
{
write-host "No datasource selected, exiting.`n" -foregroundcolor yellow
"Aborted on no Datasource index selected" >> $logfile
exit 0
}
$DSselected=$ds[$DSname]
if (!$DSselected)
{
write-host "No valid datasource selected, exiting. `n" -foregroundcolor yellow
"Aborted on invalid Datasource index number" >> $logfile
exit 0
}
if ($DSselected.Replicasize -gt 0)
{
$Replicasize=[math]::round($DSselected.Replicasize/$GB,1)
$line=("Current Replica Size = {0} GB for selected data source: $DSselected.name" -f $Replicasize)
$line >> $logfile
write-host $line`n -foregroundcolor white
}
[uint64] $NewReplicaGB=read-host "Enter new Replica size in GB"
if ($Replicasize -ge $NewReplicaGB)
{
write-host New Replica size must be greater than current size of $Replicasize GB - Exiting.
$line =("New Replica size must be greater than current size - Exiting")
$line >> $logfile
exit 0
}
$line=("New Replica Size = {0} GB " -f $NewReplicaGB)
$line >> $logfile
write-host $line`n -foregroundcolor white
# execute the resize
Write-host "Processing Resize Request. Please wait..."
$error.clear()
$DPM.Proxy.ResizeReplica($DSSelected.DataSourceID,$NewReplicaGB*$GB)
if($error)
{
$line=("Error Extending !! - aborted. ---> Verify Optimize Disk (defragsvc) Service startup type is set to Manual then retry the operation.")
$line >> $logfile
write-host $line`n -foregroundcolor red
Disconnect-dpmServer
exit 1
}
$line = "Resize Process Done ! "
write-host $line
$datetime = get-date
$line = $line + $datetime
$line >> $logfile
$line="Do you want to View $logfile file Y/N ? "
write-host $line -foregroundcolor white
$Y=read-host
$line = $line + $Y
$line >> $logfile
if ($Y -ieq "Y")
{
Notepad $logfile
}