Skip to content

Commit 0d489ab

Browse files
Create Migrate-MaintenaceSchedules.ps1
1 parent 73921e3 commit 0d489ab

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Export Maintenance Schedules from Old Management Group
2+
Import-Module OperationsManager
3+
$schedlist = Get-SCOMMaintenanceScheduleList
4+
Foreach($sched in $schedlist){
5+
$schedp = Get-SCOMMaintenanceSchedule -id $sched.ScheduleId
6+
$monobjs = $schedp.MonitoringObjects
7+
foreach($monobj in $monobjs){
8+
$obj = Get-SCOMMonitoringObject -id $monobj
9+
if ($obj.FullName -match '.Group'){
10+
$monlist += $obj.DisplayName + ";"
11+
$grp = "yes"
12+
}
13+
}
14+
$name = $schedp.ScheduleName
15+
$rec = $schedp.Recursive
16+
$enable = $schedp.IsEnabled
17+
$astart = $schedp.ActiveStartTime
18+
$aend = $schedp.ActiveEndDate
19+
$dur = $schedp.Duration
20+
$freqtype = $schedp.ScheduleRecurrence.FreqType
21+
$freqinterval = $schedp.ScheduleRecurrence.FreqInterval
22+
if($monlist -ne $null){
23+
$str = $name + "," + $rec + "," + $enable + "," + $monlist + "," + $astart + "," + $aend + "," + $dur + "," + $freqtype + "," + $freqinterval
24+
$str >> MainSchedOut.txt
25+
$monlist = $null
26+
}
27+
}
28+
29+
30+
# Import Maintenance Schedules into New Management Group
31+
Import-Module OperationsManager
32+
$maintscheds = Get-Content MainSchedOut.txt
33+
34+
foreach($maintsched in $maintscheds){
35+
$monobjids = @()
36+
$schedvs = $maintsched.split(",")
37+
$name = $schedvs[0]
38+
$rec = $schedvs[1]
39+
$enable = $schedvs[2]
40+
$monobjarr = $schedvs[3].split(";")
41+
foreach($monobj in $monobjarr){
42+
if($monobj -ne ""){
43+
44+
$monitem = Get-SCOMMonitoringObject -DisplayName $monobj
45+
$monobjid = $monitem.Id.guid
46+
if($monobjid -eq $null){
47+
$str = $monobj + " Group not found in this management group, moving to next"
48+
$str
49+
}else{
50+
$monobjids += $monobjid
51+
}
52+
}
53+
}
54+
$monobjs = $monobjids
55+
$monobjids = $null
56+
if(!($monobjs -match "-")){
57+
$str = "For Maint Sched " + $name + " No Groups Found in this Management Group, Skipping Maintenance Schedule Creation"
58+
$str
59+
}else{
60+
$astart = $schedvs[4]
61+
$aend = $schedvs[5]
62+
$dur = $schedvs[6]
63+
$freqtype = $schedvs[7]
64+
$freqinterval = [int]$schedvs[8]
65+
$str = "Creating Maint Schedule: " + $name
66+
$str
67+
New-SCOMMaintenanceSchedule -Name $name -Recursive $true -Enabled $true -MonitoringObjects $monobjs -ActiveStartTime $astart -ActiveEndDate $aend -Duration $dur -ReasonCode "PlannedOther" -Comments "Created from Powershell" -FreqType $freqtype -FreqInterval $freqinterval
68+
}
69+
}

0 commit comments

Comments
 (0)