forked from byteben/Win32App-Migration-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate-sccm-app-to-intune-public.ps1
249 lines (222 loc) · 12.3 KB
/
migrate-sccm-app-to-intune-public.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<#
.Synopsis
Created on: 2023.12.12
Created by: Martynas Atkocius
Filename: migrate-sccm-app-to-intune-public.ps1
.Description
Script to migrate SCCM application to Intune.
Powershell module dependencies:
- Win32App-Migration-Tool,
- IntuneWin32App.
#>
#region User_Variables
$SiteCode = "BB1"
$SiteServer = "SCCM1.byteben.com"
$WorkingFolder = "C:\Win32AppMigrationTool"
$Win32AppMigrationModuleFolder = "C:\Github\repos\Win32App-Migration-Tool"
$TenantId = "domain.onmicrosoft.com"
$AADClientId = ""
#endregion User_Variables
#region Static_Variables
$AppDetailsFolder = "$WorkingFolder\Details"
$WorkingFolder_Root = $WorkingFolder # Used by Write-Log function
#endregion Static_Variables
#region Dependencies
Import-Module "$Win32AppMigrationModuleFolder\Win32AppMigrationTool.psd1" -Force
Import-Module IntuneWin32App -Force
Import-Module "$Win32AppMigrationModuleFolder\Private\Write-Log.ps1"
#endregion Dependencies
### APP EXPORTING ###
$CMAppName = "*chrome*"
New-Win32App -AppName $CMAppName -ProviderMachineName $SiteServer -SiteCode $SiteCode -WorkingFolder $WorkingFolder -ExportIcon -PackageApps
### APP IMPORTING TO INTUNE
### Helper functions
#region Helper_Functions
Function ConvertTo-IntuneOperator ([string]$Operator, [switch]$RegString = $false) {
# Supported values for Intune operators are: equal, notEqual, greaterThanOrEqual, greaterThan, lessThanOrEqual or lessThan.
# Respective SCCM values are: Equals, NotEquals, GreaterEquals, GreaterThan, LessEquals, LessThan
# NB: Not all SCCM operators are supported in Intune. Additionally, reg string comparison only supports equal and notequal
$outputOperator = "NotSupportedInIntune"
if ($Operator -in ('Equals', 'NotEquals')) {
$outputOperator = $Operator.TrimEnd('s')
}
elseif ($Operator -in ('GreaterEquals', 'LessEquals') -and -not $RegString) {
$outputOperator = $Operator -replace 'Equals', 'ThanOrEqual'
}
elseif ($Operator -in ('GreaterThan', 'LessThan') -and -not $RegString) {
$outputOperator = $Operator
}
return $outputOperator
}
Function ConvertTo-IntuneAppDetectionArray ([PSCustomObject]$DetectionMethodDetails) {
$DetectionRuleArray = @()
foreach ($detectionMethod in $DetectionMethodDetails) {
$detectionRule, $detectionParams = $null
try {
if ($detectionMethod.DetectionType -eq 'Script') {
$detectionScriptFile = Resolve-Path -Path "$AppDetailsFolder\$($DetectionMethodDetails.ScriptFileName)"
$detectionRule = New-IntuneWin32AppDetectionRuleScript -ScriptFile $detectionScriptFile.Path
}
elseif ($detectionMethod.DetectionType -in ('File', 'Folder')) {
$detectionParams = @{
Path = $detectionMethod.SettingPath
FileOrFolder = $detectionMethod.SettingFileOrFolderName
Check32BitOn64System = !([System.Convert]::ToBoolean($detectionMethod.SettingIs64Bit))
}
if (!($detectionMethod.PropertyPath)) {
# Existence rule
$detectionParams.Add('Existence', $true)
$detectionParams.Add('DetectionType', 'exists')
}
else {
# Comparison rule: DateModified, DateCreated, Version, Size
$ruleType = $detectionMethod.PropertyPath
$detectionMethodOperator = ConvertTo-IntuneOperator $detectionMethod.Operator
if ($detectionMethodOperator -ne 'NotSupportedInIntune') {
$detectionParams.Add($ruleType, $true)
$detectionParams.Add('Operator', $detectionMethodOperator)
if ($ruleType -in ('DateModified', 'DateCreated')) {
$detectionDateTimeValue = [datetime]$detectionMethod.ConstValue
$detectionParams.Add('DateTimeValue', $detectionDateTimeValue)
}
elseif ($ruleType -eq 'Version') {
$detectionParams.Add('VersionValue', $detectionMethod.ConstValue)
}
elseif ($ruleType -eq 'Size') {
# We can't directly convert a file size-based rule since in SCCM size is configured in bytes while in Intune - megabytes
Write-Log -Message "Cannot directly convert file size-based detection rules - rule skipped" -LogId $LogId -Severity 2
Write-Warning "Cannot directly convert file size-based detection rules - rule skipped"
continue
}
}
else {
# Detection rule operator not supported in Intune
Write-Log -Message ("Detection rule operator '{0}' not supported in Intune - rule skipped" -f $detectionMethodOperator) -LogId $LogId -Severity 2
Write-Warning ("Detection rule operator '{0}' not supported in Intune - rule skipped" -f $detectionMethodOperator)
continue
}
}
$detectionRule = New-IntuneWin32AppDetectionRuleFile @detectionParams
}
elseif ($detectionMethod.DetectionType -in ('RegistryKey', 'Registry')) {
$detectionParams = @{
KeyPath = $detectionMethod.SettingLocation
Check32BitOn64System = !([System.Convert]::ToBoolean($detectionMethod.SettingIs64Bit))
}
if ($detectionMethod.DetectionType -eq 'Registry') {
$detectionParams.Add('ValueName', $detectionMethod.SettingValueName)
}
if ($detectionMethod.PropertyPath -match 'exists') {
# Existence rule
$detectionParams.Add('Existence', $true)
$detectionParams.Add('DetectionType', 'exists')
}
else {
# Comparison rule: String, Integer, Version
$ruleType = $detectionMethod.DataType -replace 'Int64', 'Integer'
$detectionMethodOperator = ConvertTo-IntuneOperator $detectionMethod.Operator
if ($ruleType -eq 'String') {
$detectionMethodOperator = ConvertTo-IntuneOperator $detectionMethod.Operator -RegString
}
if ($detectionMethodOperator -ne 'NotSupportedInIntune') {
$detectionParams.Add($ruleType + 'Comparison', $true)
$detectionParams.Add($ruleType + 'ComparisonOperator', $detectionMethodOperator)
$detectionParams.Add($ruleType + 'ComparisonValue', $detectionMethod.ConstValue)
}
else {
# Detection rule operator not supported in Intune
Write-Log -Message ("Detection rule operator '{0}' not supported in Intune - rule skipped" -f $detectionMethodOperator) -LogId $LogId -Severity 2
Write-Warning ("Detection rule operator '{0}' not supported in Intune - rule skipped" -f $detectionMethodOperator)
continue
}
}
$detectionRule = New-IntuneWin32AppDetectionRuleRegistry @detectionParams
}
elseif ($detectionMethod.DetectionType -eq 'MSI') {
$detectionParams = @{
ProductCode = $detectionMethod.SettingProductCode
}
if ($detectionMethod.PropertyPath) {
$detectionMethodOperator = ConvertTo-IntuneOperator $detectionMethod.Operator
$detectionParams.Add('ProductVersionOperator', $detectionMethodOperator)
$detectionParams.Add('ProductVersion', $detectionMethod.ConstValue)
}
$detectionRule = New-IntuneWin32AppDetectionRuleMSI @detectionParams
}
else {
Write-Log -Message ("Warning: Unsupported or empty detection type '{0}'" -f $detectionMethod.LogicalName) -LogId $LogId -Severity 2
Write-Host ("Warning: Unsupported or empty detection type '{0}'" -f $detectionMethod.LogicalName) -ForegroundColor Yellow
}
$DetectionRuleArray += $detectionRule
}
catch {
Write-Log -Message ("Could not convert detection method '{0}'" -f $detectionMethod.LogicalName) -LogId $LogId -Severity 3
Write-Warning -Message ("Could not convert detection method '{0}'" -f $detectionMethod.LogicalName)
Write-Warning -Message ("Error message: '{0}'" -f $_.Exception.Message)
}
}
return $DetectionRuleArray
}
#endregion Helper_Functions
try {
# Get application details from CSV files
$AppDetails = Import-Csv -Path "$AppDetailsFolder\Applications.csv" -Encoding UTF8
$DeploymentTypeDetails = Import-Csv -Path "$AppDetailsFolder\DeploymentTypes.csv" -Encoding UTF8
$DetectionMethodDetails = Import-Csv -Path "$AppDetailsFolder\DetectionMethods.csv" -Encoding UTF8
# Name, display name, description, version and publisher
# $AppDisplayName = $AppDetails.Name
$AppDisplayName = $AppDetails.DisplayName
$AppDisplayName += if (-not $AppDisplayName.EndsWith('BB')) { ' BB' } # Add an optional suffix to the app name
$AppDescription = $AppDetails.Description
$AppVersion = $AppDetails.Version
$AppPublisher = $AppDetails.Publisher
# Install and uninstall command lines
$InstallCommandLine = $DeploymentTypeDetails.InstallCommandLine
$UninstallCommandLine = $DeploymentTypeDetails.UninstallCommandLine
# Execution context and estimated installation time
$InstallExperience = $DeploymentTypeDetails.ExecutionContext
$InstallationTime = $DeploymentTypeDetails.ExecuteTime
# App icon
if ($AppDetails.IconPath) {
$AppIconFile = Get-Item -Path $AppDetails.IconPath
$AppIcon = New-IntuneWin32AppIcon -FilePath $AppIconFile.FullName
}
# Requirements
# MIGRATION NOT IMPLEMENTED
$RequirementRule = New-IntuneWin32AppRequirementRule -Architecture x64 -MinimumSupportedWindowsRelease W10_20H2
# Detection
$DetectionRuleArray = ConvertTo-IntuneAppDetectionArray -DetectionMethodDetails $DetectionMethodDetails
# Scope tag
$ScopeTagNameArray = @('YourScopeTagName')
# Content (intunewin file)
$IntuneWinFile = Get-Item "$WorkingFolder\Win32Apps\$($DeploymentTypeDetails.ApplicationName)\$($DeploymentTypeDetails.Name)\*.intunewin"
$IntuneWinMetaData = Get-IntuneWin32AppMetaData -FilePath $IntuneWinFile.FullName
### Params for Add-IntuneWin32App
$IntuneAppParams = @{
'FilePath' = $IntuneWinFile.FullName
'DisplayName' = $AppDisplayName
'Description' = $AppDescription
'AppVersion' = $AppVersion
'Publisher' = $AppPublisher
'InstallCommandLine' = $InstallCommandLine
'UninstallCommandLine' = $UninstallCommandLine
'AllowAvailableUninstall' = $true
'InstallExperience' = $InstallExperience
'RestartBehavior' = 'suppress'
'Icon' = $AppIcon
'DetectionRule' = $DetectionRuleArray
'RequirementRule' = $RequirementRule
'ScopeTagName' = $ScopeTagNameArray
}
$IntuneAppParamsForLog = $IntuneAppParams | select * -ExcludeProperty Icon | ConvertTo-Json
Write-Log -Message "Importing application into Intune with the following parameters: `n$IntuneAppParamsForLog`n" -LogId $LogId
Write-Host "Importing application into Intune with the following parameters: `n$IntuneAppParamsForLog`n" -ForegroundColor Green
Connect-MSIntuneGraph -TenantID $TenantId -ClientID $AADClientId
$AppRequest = Add-IntuneWin32App @IntuneAppParams -Verbose
$AppRequest | select * -ExcludeProperty largeIcon
}
catch {
$ErrorMsg = $_.Exception.Message
Write-Log -Message ("Could not import into Intune: application '{0}'. Error message: '{1}'" -f $AppDisplayName, $ErrorMsg) -LogId $LogId -Severity 3
Write-Warning -Message ("Could not import into Intune: application '{0}'. Error message: '{1}'" -f $AppDisplayName, $ErrorMsg)
}