#
# Cube Status Report
# Copyright 2012 Ryan McLean
# ryan !!!! 1_00 !!@!! hotmail _!=antispam_ dot com
# http://ninet.org
#
# Queries the Cube and generates a status report based
# on the Response.
#
#>
$smtpServer = "smtp.example.com" # SMTP Server to use to send the email
$rcpts = @("user1@example.com","user2@example.com") # Array of users to get the email
$tfssvr = "tfs.example.com" # TFS Server
$outfile = "C:\tmp\test.html" # File to output to if not sending email
$msubject = "[Daily Checks] Cube Status"3 # Email Subject Line
$title = "SOAP Response for GetProcessingStatus()" # Title of HTML Report
$sendemail = $true # True Sends email, False will generate outfile
$mtf = "noreply@" + $tfssvr
if ($sendemail) {
$mail = new-object Net.Mail.MailMessage
foreach ($usr in $rcpts) {
$mail.To.Add($usr)
}
$mail.From = New-Object System.Net.Mail.MailAddress($mtf)
$mail.ReplyTo = New-Object System.Net.Mail.MailAddress($mtf)
$mail.subject = $msubject
$mail.IsBodyHtml = $true
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
}
$url = "http://" + $tfssvr + ":8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx?WSDL"
try {
$TFSProcessingStatus = New-WebServiceProxy -Uri $url -UseDefaultCredential
$ProcessingStatus = $TFSProcessingStatus.GetProcessingStatus("","")
$Instances = $ProcessingStatus.Instance
$Collections = $ProcessingStatus.Collections
$arrDetails = @()
Write-Host "Processing Instances"
# Process Instances
$Instances | %{
$Detail = "" | Select Type, Name, Jobs
$Detail.Type = "Instance"
$Detail.Name = $_.Name
$arrJobs = @()
$_.Jobs | %{
$Job = "" | Select Name, Result, Starttime, EndTime, ResultMessage
$Job.Name = $_.Name
$LR = $_.LastRun
# Uncomment you only want to display errors
#if ($LR.Result -ne "Succeeded") {
$Job.Result = $LR.Result
$Job.Starttime = $LR.ExecutionStartTimeUtc
$Job.EndTime = $LR.EndTimeUtc
$Job.ResultMessage = $LR.ResultMessage
$arrJobs += $Job
#}
}
$Detail.Jobs = $arrJobs
$arrDetails += $Detail
}
Write-Host "Processing Collections"
#Process Collections
$Collections | %{
$Detail = "" | Select Type, Name, Jobs
$Detail.Type = "Collection"
$Detail.Name = $_.Name
$arrJobs = @()
$_.Jobs | %{
$Job = "" | Select Name, Result, Starttime, EndTime, ResultMessage
$Job.Name = $_.Name
$LR = $_.LastRun
# Uncomment you only want to display errors
#if (($LR.Result -ne "Succeeded") -and ($LR.Result -ne "Disabled")){
$Job.Result = $LR.Result
$Job.Starttime = $LR.ExecutionStartTimeUtc
$Job.EndTime = $LR.EndTimeUtc
$Job.ResultMessage = $LR.ResultMessage
$arrJobs += $Job
#}
}
$Detail.Jobs = $arrJobs
$arrDetails += $Detail
}
} catch [System.Net.WebException] {
Write-Host $_.Exception.ToString()
}
############### Display ############################
$html = "
$title"
$html += @"
$title
| Type |
Name |
"@
$arrdetails | % {
$type = $_.Type
$name = $_.Name
$html += @"
| $type |
$name |
"@
$html += @"
| Job Name |
Result |
Start Time |
End Time |
Result Message |
"@
$_.Jobs | % {
$jname = $_.Name
$jres = $_.Result
$jst = $_.Starttime
$jet = $_.EndTime
$jrm = $_.ResultMessage
if ($jres -eq "Succeeded") {
$html += @"
| $jname |
$jres |
$jst |
$jet |
$jrm |
"@
} elseif ($jres -eq "Blocked") {
$html += @"
| $jname |
$jres |
$jst |
$jet |
$jrm |
"@
} elseif ($jres -eq "Disabled") {
$html += @"
| $jname |
$jres |
$jst |
$jet |
$jrm |
"@
} else {
$html += @"
| $jname |
$jres |
$jst |
$jet |
$jrm |
"@
}
}
$html += @"
|
"@
}
$html += @"
"@
if ($sendemail) {
$mail.body = $html
$smtp.Send($mail)
} else {
$html | Out-File $outfile
}