forked from pdxcat/SCCMScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-sccmschedule.ps1
47 lines (40 loc) · 1.68 KB
/
get-sccmschedule.ps1
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
<#
.Synopsis
This retrieves SCCM advertisements that are scheduled for install.
.Description
This script will output the advertisements schedule for a machine. It uses WMI to find the scheduled advert
and the package information. It then it combines the output.
.Example
get-sccmschedule.ps1 <computername>
This will output the scheduled tasks.
#>
param(
[string]$CompName
)
## Graps the package information
$ScheduleList = Get-WmiObject -Namespace "root\ccm\scheduler" -Class ccm_scheduler_history -ComputerName $CompName | where -Property "ScheduleID" -Match "cat" | select ScheduleID,LastTriggerTime
$PkgInfo = Get-WmiObject -Namespace "Root\sms\Site_KAT" -Class SMS_Program -ComputerName Itzamna | select PackageID,PackageName,PackageVersion -Unique
function Format-Pkg{
foreach($Item in $ScheduleList){
$NewObject = New-Object -TypeName PSObject
$AdvertID=$Item.ScheduleID.Split('-')[0]
$PKID=$Item.ScheduleID.Split('-')[1]
$Time = Format-Date($Item.LastTriggerTime)
$NewObject | Add-Member -Type "NoteProperty" -Name PackageID -Value $PKID
$NewObject | Add-Member -Type "NoteProperty" -Name AdvertiseID -Value $AdvertID
$NewObject | Add-Member -Type "NoteProperty" -Name LastRunTime -Value $Time
$NewObject
}
}
function Format-Date{
param($Date)
$Year = $Date.SubString(0,4)
$Month = $Date.SubString(4,2)
$Day = $Date.SubString(6,2)
$Hour = $Date.SubString(8,2)
$Minute = $Date.SubString(10,2)
$Second = $Date.SubString(12,2)
"$Month/$Day/$Year $Hour`:$Minute`:$Second"
}
$FinalList = Format-Pkg
$FinalList