View the script below or
click here to download it.
I don't confess to being a PowerShell guru and I'm sure this script could be made more efficient. If your PoSh skills are better than mine and you have suggestions for improving this, please let me know using the
PowerShell Forum. Thank you.
----------
param([string] $DPMServerName)
$scomapi = new-object -comObject "MOM.ScriptAPI"$scombag = $scomapi.CreatePropertyBag()
$logerror = 1$logwarning = 2$loginfo = 4
$scriptname = "DTTCheckDataSourceState.ps1"
If(!$DPMServerName)
{
$scomapi.LogScriptEvent($scriptname, 5800, $loginfo, "No DPM server name supplied, exiting script")
Exit 0
}
$dsl = Get-Datasource -DPMServerName $DPMServerName | Where-Object {$_.Protected -eq "True"}
If(!$dsl)
{
$scomapi.LogScriptEvent($scriptname, 5800, $loginfo, "No protected data sources found")
}
Foreach($ds in $dsl)
{
If($ds.Type.Name -eq "Volume")
{
If($ds.state -eq "Valid")
{
$state = "OK"
}
Elseif($ds.state -eq "Invalid")
{
If($ds.activity -eq "Validating")
{
$state = "OK"
}
Else
{
$state = "ERROR"
}
}
}
ElseIf($ds.Type.Name -match "SQL*")
{
If($ds.state -eq "Valid")
{
$state = "OK"
}
ElseIf($ds.state -eq "Invalid")
{
If($ds.activity -eq "Validating")
{
$state = "OK"
}
Else
{
$state = "ERROR"
}
}
}
EelseIf($ds.Type.Name -eq "FileGroup")
{
If($ds.state -eq "Valid")
{
$state = "OK"
}
ElseIf($ds.state -eq "Invalid")
{
If($ds.activity -eq "Validating")
{
$state = "OK"
}
Else
{
$state = "ERROR"
}
}
}
ElseIf($ds.Type.Name -eq "Storage group")
{
If($ds.state -eq "Valid")
{
$state = "OK"
}
ElseIf($ds.state -eq "Invalid")
{
If($ds.activity -eq "Validating")
{
$state = "OK"
}
Else
{
$state = "ERROR"
}
}
}
elseif($ds.Type.Name -eq "Sharepoint farm")
{
if($ds.state -eq "Valid")
{
$state = "OK"
}
elseif($ds.state -eq "Invalid")
{
if($ds.activity -eq "Validating")
{
$state = "OK"
}
else
{
$state = "ERROR"
}
}
}
elseif($ds.Type.Name -eq "Windows Sharepoint Services Search")
{
if($ds.state -eq "Valid")
{
$state = "OK"
}
elseif($ds.state -eq "Invalid")
{
if($ds.activity -eq "Validating")
{
$state = "OK"
}
else
{
$state = "ERROR"
}
}
}
elseif($ds.Type.Name -eq "Exchange Mailbox Database")
{
if($ds.state -eq "Valid")
{
$state = "OK"
}
elseif($ds.state -eq "Invalid")
{
if($ds.activity -eq "Validating")
{
$state = "OK"
}
else
{
$state = "ERROR"
}
}
}
elseif($ds.Type.Name -eq "System Protection")
{
if($ds.state -eq "Valid")
{
$state = "OK"
}
elseif($ds.state -eq "Invalid")
{
if($ds.activity -eq "Validating")
{
$state = "OK"
}
else
{
$state = "ERROR"
}
}
}
else
{
$scomapi.LogScriptEvent($scriptname, 5802, $loginfo, "Datasource type $($ds.Type.Name) for $($ds.Name) is not recognised")
}
$bag = $scomapi.CreatePropertyBag()
$bag.AddValue('DatasourceName',$ds.name)
$bag.AddValue('ProductionServerName',$ds.ProductionServerName)
$bag.AddValue('Status',$state) $bag.AddValue('DSID',$ds.id.guid)
$bag
}