-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIdentify-Content.ps1
157 lines (133 loc) · 5.06 KB
/
Identify-Content.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<#
.SYNOPSIS
Identify Configuration Manager Content from PackageID in Errors and Log Files
.DESCRIPTION
Uses PackageID to Identify Content Type and Other Descriptive Information About Content, Requires - Created by Mark Godfrey @Geodesicz
.PARAMETER SiteServer
The computer name of your Configuration Manager site server to query
.PARAMETER SiteCode
The Site Code of your Configuration Manager site to query
.PARAMETER PackageID
The PackageID of the Content you are attempting to identify
.EXAMPLE
.\Identify-Content.ps1 -SiteServer 'teku-cm' -SiteCode 'PS1' -PackageID 'PS10008B' -Verbose
.LINK
http://www.tekuits.com
#>
[CmdletBinding()]
Param(
[Parameter(HelpMessage="SiteServer")]
[ValidateNotNullOrEmpty()]
[String]$SiteServer,
[Parameter(HelpMessage="SiteCode")]
[ValidateNotNullOrEmpty()]
[String]$SiteCode,
[Parameter(Mandatory=$true,HelpMessage="PackageID")]
[ValidateNotNullOrEmpty()]
[String]$PackageID
)
If($siteserver -eq $null -or $SiteCode -eq $null){
# Import Configuration Manager Module
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
# Get Site Information
$siteserver = Get-PSDrive -PSProvider CMSite | select -ExpandProperty Root
$sitecode = Get-PSDrive -PSProvider CMSite | select -ExpandProperty Name
}
If($siteserver -eq $null -or $SiteCode -eq $null){Write-Error "SiteServer or SiteCode variables not defined. Either specify as parameters or run on system with Configuration Manager Module to automatically import."}
# Define Namespace from Site Code
Write-Verbose "Defining Namespace From Site Code"
$Namespace = "root\sms\site_$sitecode"
# Functions
function Query-CMWQL {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,Position=1)]
[ValidateNotNullorEmpty()]
[String]$WQLQuery
)
Get-WmiObject -ComputerName $SiteServer -Namespace $Namespace -Query $WQLQuery
}
# Check if Package
Write-Verbose "Checking if Content is a Package"
$Package = Query-CMWQL "SELECT * from sms_package where packageid = '$PackageID'"
If($Package -ne $null){
$ObjectType = 'Package'
$Object = $Package
Write-Verbose "Content Type Identified"
}
If($ObjectType -eq $null){
# Check if Application
Write-Verbose "Checking if Content is an Application"
$Application = Query-CMWQL "SELECT * from sms_contentpackage where packageid = '$PackageID'"
If($Application -ne $null){
$ObjectType = 'Application'
$Object = $Application
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if Boot Image
Write-Verbose "Checking if Content is a Boot Image"
$BootImage = Query-CMWQL "SELECT * from sms_bootimagepackage where packageid = '$PackageID'"
If($BootImage -ne $null){
$ObjectType = 'Boot Image'
$Object = $BootImage
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if OS Image
Write-Verbose "Checking if Content is an Operating System Image"
$OSImage = Query-CMWQL "SELECT * from sms_imagepackage where packageid = '$PackageID'"
If($OSImage -ne $null){
$ObjectType = 'Operating System Image'
$Object = $OSImage
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if Software Update Package
Write-Verbose "Checking if Content is a Software Update Package"
$SUP = Query-CMWQL "SELECT * from sms_softwareupdatespackage where packageid = '$PackageID'"
If($SUP -ne $null){
$ObjectType = 'Software Update Package'
$Object = $SUP
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if Driver Package
Write-Verbose "Checking if Content is a Driver Package"
$DrvPkg = Query-CMWQL "SELECT * from sms_driverpackage where packageid = '$PackageID'"
If($DrvPkg -ne $null){
$ObjectType = 'Driver Package'
$Object = $DrvPkg
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if Operating System Upgrade/Install Package
Write-Verbose "Checking if Content is an Operating System Upgrade/Install Package"
$OSUpgPkg = Query-CMWQL "SELECT * from sms_operatingsysteminstallpackage where packageid = '$PackageID'"
If($OSUpgPkg -ne $null){
$ObjectType = 'Operating System Upgrade/Install Package'
$Object = $OSUpgPkg
Write-Verbose "Content Type Identified"
}
}
If($ObjectType -eq $null){
# Check if Virtual Hard Disk
Write-Verbose "Checking if Virtual Hard Disk"
$VHD = Query-CMWQL "SELECT * from sms_vhdpackage where packageid = '$PackageID'"
If($VHD -ne $null){
$ObjectType = 'Virtual Hard Disk'
$ObjectType = $VHD
Write-Verbose "Content Type Identified"
}
}
# Feedback
If($ObjectType -eq $null){Write-Error "Unable to Identify Content"}
else{
Write-Verbose "Content Type is $ObjectType"
$Object
}