forked from MSEndpointMgr/M365Apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisioWin32DetectionScript.ps1
214 lines (174 loc) · 9.99 KB
/
VisioWin32DetectionScript.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
########################################################################
# Detection Script for Microsoft Visio
# Created by Matt Lavine [@mattlavine](https://github.com/mattlavine)
# Contains code forked from @JankeSkanke
########################################################################
#DetectionScript
function Write-LogEntry {
param (
[parameter(Mandatory = $true, HelpMessage = "Value added to the log file.")]
[ValidateNotNullOrEmpty()]
[string]$Value,
[parameter(Mandatory = $true, HelpMessage = "Severity for the log entry. 1 for Informational, 2 for Warning and 3 for Error.")]
[ValidateNotNullOrEmpty()]
[ValidateSet("1", "2", "3")]
[string]$Severity,
[parameter(Mandatory = $false, HelpMessage = "Name of the log file that the entry will written to.")]
[ValidateNotNullOrEmpty()]
[string]$FileName = $LogFileName
)
# Determine log file location
$LogFilePath = Join-Path -Path $env:SystemRoot -ChildPath $("Temp\$FileName")
# Construct time stamp for log entry
$Time = -join @((Get-Date -Format "HH:mm:ss.fff"), " ", (Get-WmiObject -Class Win32_TimeZone | Select-Object -ExpandProperty Bias))
# Construct date for log entry
$Date = (Get-Date -Format "MM-dd-yyyy")
# Construct context for log entry
$Context = $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
# Construct final log entry
$LogText = "<![LOG[$($Value)]LOG]!><time=""$($Time)"" date=""$($Date)"" component=""$($LogFileName)"" context=""$($Context)"" type=""$($Severity)"" thread=""$($PID)"" file="""">"
# Add value to log file
try {
Out-File -InputObject $LogText -Append -NoClobber -Encoding Default -FilePath $LogFilePath -ErrorAction Stop
if ($Severity -eq 1) {
Write-Verbose -Message $Value
} elseif ($Severity -eq 3) {
Write-Warning -Message $Value
}
} catch [System.Exception] {
Write-Warning -Message "Unable to append log entry to $LogFileName.log file. Error message at line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)"
}
}
#--------------------------------------------------
#--------------------------------------------------
#--------------------------------------------------
#--------------------------------------------------
# List of Product IDs that are supported by the Office Deployment Tool for Click-to-Run
# https://learn.microsoft.com/en-us/microsoft-365/troubleshoot/installation/product-ids-supported-office-deployment-click-to-run
#--------------------------------------------------
# (REQUIRED) The Display Name for the App Install to match against. This is a CONTAINS match, not an EXACT match, to account for the culture code (ex. "en-us") being appended to the display name.
$RequiredM365AppsDisplayName = "Microsoft Visio"
# (REQUIRED) The Bit Version/Architecture of the App Install ("x64" or "x86")
$RequiredPlatform = "x64"
# (REQUIRED) The Download method of the install (ex. "Local", "CDN")
$RequiredMediaType = "CDN"
# (REQUIRED) The Required ProductReleaseID to check
$RequiredProductReleaseID = "VisioProRetail"
# (OPTIONAL) List of Required M365 Excluded Apps to check. The list is a CONTAINS match, not an EXACT match. As long as the list found contains AT LEAST these items then it will pass.
$RequiredM365ExcludedApps = @()
#--------------------------------------------------
$RegistryUninstallKeys = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$ClickToRunConfigurationRegistryPath = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
#--------------------------------------------------
#--------------------------------------------------
#--------------------------------------------------
#--------------------------------------------------
$LogFileName = "M365AppsSetup.log"
Write-LogEntry -Value "Starting `"$RequiredM365AppsDisplayName`" install detection logic" -Severity 1
#--------------------------------------------------
# Get the Display Name for the current Microsoft 365 Apps install
$M365AppsDisplayNameCheck = $RegistryUninstallKeys | Get-ItemProperty | Where-Object { $_.DisplayName -match $RequiredM365AppsDisplayName }
if ($RequiredM365AppsDisplayName) {
Write-LogEntry -Value "The following Microsoft 365 App install is REQUIRED: `"$RequiredM365AppsDisplayName`"" -Severity 1
}
# add line for if key does not exist
if ($M365AppsDisplayNameCheck) {
Write-LogEntry -Value "The following Microsoft 365 App install was FOUND: `"$(($M365AppsDisplayNameCheck).DisplayName)`"" -Severity 1
} else {
Write-LogEntry -Value "A matching Microsoft 365 App install was NOT FOUND." -Severity 2
}
#--------------------------------------------------
# Get the Platform registry key
$Platform = (Get-ItemProperty -Path $ClickToRunConfigurationRegistryPath -Name "Platform" -ErrorAction SilentlyContinue).Platform
if ($RequiredPlatform) {
Write-LogEntry -Value "The following Platform is REQUIRED: `"$RequiredPlatform`"" -Severity 1
}
# add line for if key does not exist
if ($Platform) {
Write-LogEntry -Value "The following Platform was FOUND: `"$Platform`"" -Severity 1
} else {
Write-LogEntry -Value "The Platform key was empty or didn't exist." -Severity 2
}
#--------------------------------------------------
# Check the MediaType registry key (formatted as "[ProductReleaseID].MediaType" - e.g. "O365ProPlusRetail.MediaType") for the download method used for install. Example: "Local", "CDN"
$MediaType = (Get-ItemProperty -Path $ClickToRunConfigurationRegistryPath -Name "$RequiredProductReleaseID.MediaType" -ErrorAction SilentlyContinue)."$RequiredProductReleaseID.MediaType"
if ($RequiredMediaType) {
Write-LogEntry -Value "The following MediaType (`"$RequiredProductReleaseID.MediaType`") is REQUIRED: `"$RequiredMediaType`"" -Severity 1
}
# add line for if key does not exist
if ($MediaType) {
Write-LogEntry -Value "The following MediaType (`"$RequiredProductReleaseID.MediaType`") was FOUND: `"$MediaType`"" -Severity 1
} else {
Write-LogEntry -Value "The MediaType key was empty or didn't exist." -Severity 2
}
#--------------------------------------------------
# Check the ProductReleaseIds registry key for a list of items
$ProductReleaseIDs = (Get-ItemProperty -Path $ClickToRunConfigurationRegistryPath -Name "ProductReleaseIds" -ErrorAction SilentlyContinue).ProductReleaseIds
$ProductReleaseIDList = $ProductReleaseIDs -split ','
if ($RequiredProductReleaseID) {
Write-LogEntry -Value "The following ProductReleaseId is REQUIRED: `"$RequiredProductReleaseID`"" -Severity 1
}
# add line for if key is not found
if ($ProductReleaseIDs) {
Write-LogEntry -Value "The following ProductReleaseIds were FOUND: `"$ProductReleaseIDs`"" -Severity 1
} else {
Write-LogEntry -Value "The ProductReleaseIds key was empty or didn't exist." -Severity 2
}
# Assume the required ProductReleaseID isn't present until proven otherwise. Compare it to the list of installed ProductReleaseIDs
$RequiredProductReleaseIDPresent = $false
if ($ProductReleaseIDList -contains $RequiredProductReleaseID) {
$RequiredProductReleaseIDPresent = $true
}
#--------------------------------------------------
# Skip this section if $RequiredM365ExcludedApps was left empty
if (-not $RequiredM365ExcludedApps) {
Write-LogEntry -Value "(NOT APPLICABLE) Required Excluded Apps were not configured. Skipping..." -Severity 1
$AllRequiredM365ExcludedAppsPresent = $true
} else {
# Proceed with this section if $RequiredM365ExcludedApps was configured
# Check the ExcludedApps registry key (formatted as "[ProductReleaseID].ExcludedApps" - e.g. "O365ProPlusRetail.ExcludedApps") for a list of excluded apps
$M365ExcludedApps = (Get-ItemProperty -Path $ClickToRunConfigurationRegistryPath -Name "$RequiredProductReleaseID.ExcludedApps" -ErrorAction SilentlyContinue)."$RequiredProductReleaseID.ExcludedApps"
$M365ExcludedAppsList = $M365ExcludedApps -split ','
if ($RequiredM365ExcludedApps) {
Write-LogEntry -Value "The following ExcludedApps (`"$RequiredProductReleaseID.ExcludedApps`") are REQUIRED: `"$RequiredM365ExcludedApps`"" -Severity 1
}
# add line for if key does not exist
if ($M365ExcludedApps) {
Write-LogEntry -Value "The following ExcludedApps (`"$RequiredProductReleaseID.ExcludedApps`") were FOUND: `"$M365ExcludedApps`"" -Severity 1
} else {
Write-LogEntry -Value "The ExcludedApps key was empty or didn't exist." -Severity 2
}
$AllRequiredM365ExcludedAppsPresent = $true
# Loop through the list of required Excluded Apps in the registry and mark the variable as false if any of them aren't found in the list
foreach ($M365ExcludedApp in $RequiredM365ExcludedApps) {
if (-not ($M365ExcludedAppsList -contains $M365ExcludedApp)) {
$AllRequiredM365ExcludedAppsPresent = $false
break
}
}
}
#--------------------------------------------------
if ($M365AppsDisplayNameCheck -and ($Platform -eq $RequiredPlatform) -and ($MediaType -eq $RequiredMediaType) -and $RequiredProductReleaseIDPresent -and $AllRequiredM365ExcludedAppsPresent) {
Write-LogEntry -Value "All detection conditions were met successfully." -Severity 1
Write-Output "All detection conditions were met successfully."
exit 0
} else {
if (-not $M365AppsDisplayNameCheck) {
Write-LogEntry -Value "`"$RequiredM365AppsDisplayName`" was not detected. This is not the desired state." -Severity 2
}
if ($Platform -ne $RequiredPlatform) {
Write-LogEntry -Value "Platform was not set to `"$RequiredPlatform`". This is not the desired state." -Severity 2
}
if ($MediaType -ne $RequiredMediaType) {
Write-LogEntry -Value "MediaType was not set to `"$RequiredMediaType`". This is not the desired state." -Severity 2
}
if (-not $RequiredProductReleaseIDPresent) {
Write-LogEntry -Value "The required ProductReleaseId (`"$RequiredProductReleaseID`") was not found. This is not the desired state." -Severity 2
}
if (-not $AllRequiredM365ExcludedAppsPresent) {
Write-LogEntry -Value "Not all required ExcludedApps (`"$RequiredM365ExcludedApps`") were listed. This is not the desired state." -Severity 2
}
Write-LogEntry -Value "One or more detections conditions have not been met. Detection has failed." -Severity 3
#Write-Output "One or more detections conditions have not been met. Detection has failed."
exit 1
}