-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSync_Export_RunHistory_Details.ps1
More file actions
116 lines (98 loc) · 5.04 KB
/
Sync_Export_RunHistory_Details.ps1
File metadata and controls
116 lines (98 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#############################################################################################
# Written By: Dave Hodge, MCS
# Date: 4/2/2020
# Purpose Export run history times from synchronization history
#############################################################################################
param(
[Parameter(Position=0,mandatory=$false)]
[DateTime] $Start,
[Parameter(Position=1,mandatory=$false)]
[DateTime] $End,
[Parameter(Position=2,mandatory=$false)]
[String] $Computer)
# Check local time
$DST = ([System.TimeZoneInfo]::ConvertTimeFromUtc(
(get-date).ToString(),
[System.TimeZoneInfo]::FindSystemTimeZoneById("Pacific Standard Time")
))
$DTOffset = $DST - $DST.ToLocalTime()
$Offset = $DTOffset.TotalHours
If (($Start -eq "") -or ($End -eq "") -or ($Computer -eq ""))
{
Write-Host "To export job history:" -ForegroundColor Green
Write-Host " - You must supply the start and end dates" -ForegroundColor Green
Write-Host " - The date fields must be in the following format: 'MM/DD/YYYY HH:MM:SS'" -ForegroundColor Green
Write-Host " - The computer name of the sync server must be supplied, a period can be used to reflect localhost" -ForegroundColor Green
Write-Host ""
Write-Host "e.g. RunHistory.ps1 -Start '3/21/2020 00:00:00' -End '3/26/2021 12:00:00' -Computer ." -ForegroundColor Green
Exit
}
$strStart =$Start.AddHours($OffSet).ToString('yyyy-MM-dd HH:mm:ss.fff')
$strEnd = $End.AddHours($OffSet).ToString('yyyy-MM-dd HH:mm:ss.fff')
#Build query filter
$GetRunStartTime="RunStartTime >= '$($strStart)' and RunEndTime <= '$($strEnd)'"
#Get all run history for a particular sequence of running job
$GetRunHistory = Get-WmiObject -class "MIIS_RunHistory" -namespace root\MicrosoftIdentityintegrationServer -ComputerName $Computer -Filter $GetRunStartTime
If (Test-path .\history.txt)
{
erase .\history.txt
}
"MA`tRun Profile`tResults`tStart Time`tEndTime`tTotal Time" | out-file ".\history.txt" -append
#Do something if there is history...
if($GetRunHistory -ne $null)
{
# Loop through all of the steps
foreach($Run_History in $GetRunHistory)
{
[xml]$gRunHistory = $Run_History.RunDetails().ReturnValue
$MA_Name = $gRunHistory.'run-history'.'run-details'.'ma-name'
$MA_RUN=$gRunHistory.'run-history'.'run-details'.'run-number'
$MA_RUNPROFILENAME=$gRunHistory.'run-history'.'run-details'.'run-profile-name'
#step-details information
$GetRunStepDetails= $gRunHistory.'run-history'.'run-details'.'step-details'
$errs = $null
$strType = $null
[DateTime]$dtStart = $($getrunstepdetails.'start-date')
[DateTime]$dtEnd = $($getrunstepdetails.'end-date')
[TimeSpan]$dtTotal = $dtEnd.Subtract($dtStart)
Write-Host $($getrunstepdetails.'step-result')
write-host "$($ma_name)`t$($ma_runprofilename)`t$($getrunstepdetails.'step-result')`t$($dtStart.ToLocalTime())`t$($dtEnd.ToLocalTime())`t$($dtTotal.ToString())"
"$($ma_name)`t$($ma_runprofilename)`t$($getrunstepdetails.'step-result')`t$($dtStart.ToLocalTime())`t$($dtEnd.ToLocalTime())`t$($dtTotal.ToString())" | out-file ".\history.txt" -append
#############################################################################
# Pathing to Stage-Delete...
#############################################################################
# $gRunHistory.'run-history'.'run-details'.'step-details'.'staging-counters'.'stage-delete'
# <#
foreach($runstep in $GetRunStepDetails)
{
if ($runstep.'synchronization-errors'.InnerXml -ne $null)
{
if ($runstep.'synchronization-errors'.InnerXml.Contains("<export-error"))
{
$strType = "export"
$errs = $runstep.'synchronization-errors'.'export-error'
}
else
{
$strType = "import"
$errs = $runstep.'synchronization-errors'.'import-error'
}
if ($errs -ne $null)
{
If ($errs.Count -gt 0)
{
for($i=0;$i -lt $errs.count;$i++)
{
write-host "'$ma_name'," + "'$($runstep.'step-number')'," + "'$($runstep.'step-result')'," + "'$($errs[$i].dn)'," + "'$($errs[$i].'retry-count')'," + "'$($errs[$i].'date-occurred')'," + "'$($errs[$i].'first-occurred')'," + "'$($runstep.'start-date')'," + "'$($errs[$i].'error-type')'," + "'$strType'"
}
}
Else
{
write-host "'$ma_name'," + "'$($runstep.'step-number')'," + "'$($runstep.'step-result')'," + "'$($errs.dn)'," + "'$($errs.'retry-count')'," + "'$($errs.'date-occurred')'," + "'$($errs.'first-occurred')'," + "'$($runstep.'start-date')'," + "'$($errs.'error-type')'," + "'$strType'"
}
}
}
}
#>
}
}