CLI Script: Run consistency check on invalid datasources - The Official System Center Data Protection Manager Team Blog - Site Home - TechNet Blogs

CLI Script: Run consistency check on invalid datasources

CLI Script: Run consistency check on invalid datasources

  • Comments 1
  • Likes
This script runs a consistency check job on all the protected datasources that are in the invalid state and tracks the set of jobs while giving progress on the screen. Save this script as a .ps1 file and run it. Usage and examples of scripts can be found by calling them with ‘-?’ or ‘-help’ from inside DPM Management Shell.

This is for manually running the job. Btw, for running the check on a regular scheduled basis, then use Get/Set-ProtectionJobStartTime and DPM will automatically run the consistency check (for all datasources) at the specified time.

----------------------------------- Start of Script --------------------------------

param ([string] $DPMServerName)

if(("-?","-help") -contains $args[0])
{
    Write-Host "Description: This script runs a consistency check on all the actively protected datasources which are not in valid state."
    Write-Host "Usage: Validate-InvalidDatasources.ps1 [-DPMServerName] <Name of the DPM server>"
    Write-Host "Example: Validate-InvalidDatasources.ps1 mohitc02"

    exit 0
}

if (!$DPMServerName)
{
    $DPMServerName = Read-Host "DPM server name"

    if (!$DPMServerName)
    {
        Write-Error "Dpm server name not specified."
        exit 1
    }
}

if (!(Connect-DPMServer $DPMServerName))
{
    Write-Error "Failed to connect To DPM server $DPMServerName"
    exit 1
}

$jobList = @()
foreach ($datasource in @(Get-Datasource -DPMServerName $DPMServerName | ? {$_.Protected -and $_.State -eq "Invalid"}))
{
    $jobList += @{Job = Start-DatasourceConsistencyCheck -Datasource $datasource; Datasource = $($datasource.LogicalPath)}
}

$completedJobsCount = 0
while ($completedJobsCount -ne $jobList.Length)
{
    $completedJobsCount = 0
    Write-Host ""

    foreach ($jobHT in $jobList)
    {
        if ($jobHT.Job.HasCompleted)
        {
            Write-Host "Consistency check on $($jobHT.Datasource) completed. Status: $(($jobHT.Job).Status)"
            $completedJobsCount += 1
        }
        else
        {
            Write-Host "Runnning consistency check on $($jobHT.Datasource)..."
        }
    }

    sleep 5
}

--------------------------------- End of script -------------------------------------

- Mohit Chakraborty

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment