Skip to content

Commit 21647f8

Browse files
authored
Merge pull request #313 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents a22892a + 292d64f commit 21647f8

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

Modules/CIPPCore/Public/GraphHelper/Get-NormalizedError.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ function Get-NormalizedError {
33
.FUNCTIONALITY
44
Internal
55
#>
6+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingEmptyCatchBlock', '', Justification = 'CIPP does not use this function to catch errors')]
67
[CmdletBinding()]
78
param (
89
[string]$message
@@ -21,16 +22,16 @@ function Get-NormalizedError {
2122

2223
#We need to check if the message is in one of these fields, and if so, return it.
2324
if ($JSONMsg.error.innererror.message) {
24-
Write-Host "innererror.message found: $($JSONMsg.error.innererror.message)"
25+
Write-Information "innererror.message found: $($JSONMsg.error.innererror.message)"
2526
$message = $JSONMsg.error.innererror.message
2627
} elseif ($JSONMsg.error.message) {
27-
Write-Host "error.message found: $($JSONMsg.error.message)"
28+
Write-Information "error.message found: $($JSONMsg.error.message)"
2829
$message = $JSONMsg.error.message
2930
} elseif ($JSONMsg.error.details.message) {
30-
Write-Host "error.details.message found: $($JSONMsg.error.details.message)"
31+
Write-Information "error.details.message found: $($JSONMsg.error.details.message)"
3132
$message = $JSONMsg.error.details.message
3233
} elseif ($JSONMsg.error.innererror.internalException.message) {
33-
Write-Host "error.innererror.internalException.message found: $($JSONMsg.error.innererror.internalException.message)"
34+
Write-Information "error.innererror.internalException.message found: $($JSONMsg.error.innererror.internalException.message)"
3435
$message = $JSONMsg.error.innererror.internalException.message
3536
}
3637

@@ -46,7 +47,7 @@ function Get-NormalizedError {
4647
'*User was not found.*' { 'The relationship between this tenant and the partner has been dissolved from the tenant side.' }
4748
'*AADSTS50020*' { 'AADSTS50020: The user you have used for your Secure Application Model is a guest in this tenant, or your are using GDAP and have not added the user to the correct group. Please delete the guest user to gain access to this tenant' }
4849
'*AADSTS50177' { 'AADSTS50177: The user you have used for your Secure Application Model is a guest in this tenant, or your are using GDAP and have not added the user to the correct group. Please delete the guest user to gain access to this tenant' }
49-
'*invalid or malformed*' { 'The request is malformed. Have you finished the SAM Setup?' }
50+
'*invalid or malformed*' { 'The request is malformed. Have you finished the Setup Wizard' }
5051
'*Windows Store repository apps feature is not supported for this tenant*' { 'This tenant does not have WinGet support available' }
5152
'*AADSTS650051*' { 'The application does not exist yet. Try again in 30 seconds.' }
5253
'*AppLifecycle_2210*' { 'Failed to call Intune APIs: Does the tenant have a license available?' }
@@ -58,15 +59,15 @@ function Get-NormalizedError {
5859
'*Authentication failed. MFA required*' { 'Authentication failed. MFA required' }
5960
'*Your tenant is not licensed for this feature.*' { 'Required license not available for this tenant' }
6061
'*AADSTS65001*' { 'We cannot access this tenant as consent has not been given, please try refreshing the CPV permissions in the application settings menu.' }
61-
'*AADSTS700082*' { 'The CIPP user access token has expired. Run the SAM Setup wizard to refresh your tokens.' }
62+
'*AADSTS700082*' { 'The CIPP user access token has expired. Run the Setup Wizard to refresh your tokens.' }
6263
'*Account is not provisioned.' { 'The account is not provisioned. You do not the correct M365 license to access this information..' }
6364
'*AADSTS5000224*' { 'This resource is not available - Has this tenant been deleted?' }
6465
'*AADSTS53003*' { 'Access has been blocked by Conditional Access policies. Please check the Conditional Access configuration documentation' }
6566
'*AADSTS900023*' { 'This tenant is not available for this operation. Please check the selected tenant and try again.' }
6667
'*AADSTS9002313*' { 'The credentials used to connect to the Graph API are not available, please retry. If this issue persists you may need to execute the SAM wizard.' }
6768
'*One or more platform(s) is/are not configured for the customer. Please configure the platform before trying to purchase a SKU.*' { 'One or more platform(s) is/are not configured for the customer. Please configure the platform before trying to purchase a SKU.' }
6869
"One or more added object references already exist for the following modified properties: 'members'." { 'This user is already a member of the selected group.' }
69-
Default { $message }
70+
default { $message }
7071

7172
}
7273
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutopilotProfile.ps1

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,44 @@ function Invoke-CIPPStandardAutopilotProfile {
4343

4444
# Get the current configuration
4545
try {
46+
# Replace variables in displayname to prevent duplicates
47+
$DisplayName = Get-CIPPTextReplacement -Text $Settings.DisplayName -TenantFilter $Tenant
48+
4649
$CurrentConfig = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -tenantid $Tenant |
47-
Where-Object { $_.displayName -eq $Settings.DisplayName } |
48-
Select-Object -Property displayName, description, deviceNameTemplate, language, enableWhiteGlove, extractHardwareHash, outOfBoxExperienceSetting, preprovisioningAllowed
50+
Where-Object { $_.displayName -eq $DisplayName } |
51+
Select-Object -Property displayName, description, deviceNameTemplate, language, enableWhiteGlove, extractHardwareHash, outOfBoxExperienceSetting, preprovisioningAllowed
4952

5053
if ($Settings.NotLocalAdmin -eq $true) { $userType = 'Standard' } else { $userType = 'Administrator' }
5154
if ($Settings.SelfDeployingMode -eq $true) { $DeploymentMode = 'shared' } else { $DeploymentMode = 'singleUser' }
52-
if ($Settings.AllowWhiteGlove -eq $true) {$Settings.HideChangeAccount = $true}
55+
if ($Settings.AllowWhiteGlove -eq $true) { $Settings.HideChangeAccount = $true }
5356

54-
$StateIsCorrect = ($CurrentConfig.displayName -eq $Settings.DisplayName) -and
55-
($CurrentConfig.description -eq $Settings.Description) -and
56-
($CurrentConfig.deviceNameTemplate -eq $Settings.DeviceNameTemplate) -and
57-
([string]::IsNullOrWhiteSpace($CurrentConfig.language) -and [string]::IsNullOrWhiteSpace($Settings.Languages.value) -or $CurrentConfig.language -eq $Settings.Languages.value) -and
58-
($CurrentConfig.enableWhiteGlove -eq $Settings.AllowWhiteGlove) -and
59-
($CurrentConfig.extractHardwareHash -eq $Settings.CollectHash) -and
60-
($CurrentConfig.outOfBoxExperienceSetting.deviceUsageType -eq $DeploymentMode) -and
61-
($CurrentConfig.outOfBoxExperienceSetting.escapeLinkHidden -eq $Settings.HideChangeAccount) -and
62-
($CurrentConfig.outOfBoxExperienceSetting.privacySettingsHidden -eq $Settings.HidePrivacy) -and
63-
($CurrentConfig.outOfBoxExperienceSetting.eulaHidden -eq $Settings.HideTerms) -and
64-
($CurrentConfig.outOfBoxExperienceSetting.userType -eq $userType) -and
65-
($CurrentConfig.outOfBoxExperienceSetting.keyboardSelectionPageSkipped -eq $Settings.AutoKeyboard)
66-
}
67-
catch {
57+
$StateIsCorrect = ($CurrentConfig.displayName -eq $DisplayName) -and
58+
($CurrentConfig.description -eq $Settings.Description) -and
59+
($CurrentConfig.deviceNameTemplate -eq $Settings.DeviceNameTemplate) -and
60+
([string]::IsNullOrWhiteSpace($CurrentConfig.language) -and [string]::IsNullOrWhiteSpace($Settings.Languages.value) -or $CurrentConfig.language -eq $Settings.Languages.value) -and
61+
($CurrentConfig.enableWhiteGlove -eq $Settings.AllowWhiteGlove) -and
62+
($CurrentConfig.extractHardwareHash -eq $Settings.CollectHash) -and
63+
($CurrentConfig.outOfBoxExperienceSetting.deviceUsageType -eq $DeploymentMode) -and
64+
($CurrentConfig.outOfBoxExperienceSetting.escapeLinkHidden -eq $Settings.HideChangeAccount) -and
65+
($CurrentConfig.outOfBoxExperienceSetting.privacySettingsHidden -eq $Settings.HidePrivacy) -and
66+
($CurrentConfig.outOfBoxExperienceSetting.eulaHidden -eq $Settings.HideTerms) -and
67+
($CurrentConfig.outOfBoxExperienceSetting.userType -eq $userType) -and
68+
($CurrentConfig.outOfBoxExperienceSetting.keyboardSelectionPageSkipped -eq $Settings.AutoKeyboard)
69+
} catch {
6870
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
6971
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to check Autopilot profile: $ErrorMessage" -sev Error
7072
$StateIsCorrect = $false
7173
}
7274

7375
# Remediate if the state is not correct
74-
If ($Settings.remediate -eq $true) {
76+
if ($Settings.remediate -eq $true) {
7577
if ($StateIsCorrect -eq $true) {
76-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' already exists" -sev Info
78+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' already exists" -sev Info
7779
} else {
7880
try {
7981
$Parameters = @{
8082
tenantFilter = $Tenant
81-
displayName = $Settings.DisplayName
83+
displayName = $DisplayName
8284
description = $Settings.Description
8385
userType = $userType
8486
DeploymentMode = $DeploymentMode
@@ -95,9 +97,9 @@ function Invoke-CIPPStandardAutopilotProfile {
9597

9698
Set-CIPPDefaultAPDeploymentProfile @Parameters
9799
if ($null -eq $CurrentConfig) {
98-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Created Autopilot profile '$($Settings.DisplayName)'" -sev Info
100+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Created Autopilot profile '$($DisplayName)'" -sev Info
99101
} else {
100-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Updated Autopilot profile '$($Settings.DisplayName)'" -sev Info
102+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Updated Autopilot profile '$($DisplayName)'" -sev Info
101103
}
102104
} catch {
103105
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
@@ -108,19 +110,19 @@ function Invoke-CIPPStandardAutopilotProfile {
108110
}
109111

110112
# Report
111-
If ($Settings.report -eq $true) {
113+
if ($Settings.report -eq $true) {
112114
$FieldValue = $StateIsCorrect -eq $true ? $true : $CurrentConfig
113115
Set-CIPPStandardsCompareField -FieldName 'standards.AutopilotProfile' -FieldValue $FieldValue -TenantFilter $Tenant
114116
Add-CIPPBPAField -FieldName 'AutopilotProfile' -FieldValue [bool]$StateIsCorrect -StoreAs bool -Tenant $Tenant
115117
}
116118

117119
# Alert
118-
If ($Settings.alert -eq $true) {
119-
If ($StateIsCorrect -eq $true) {
120-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' exists" -sev Info
120+
if ($Settings.alert -eq $true) {
121+
if ($StateIsCorrect -eq $true) {
122+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' exists" -sev Info
121123
} else {
122-
Write-StandardsAlert -message "Autopilot profile '$($Settings.DisplayName)' do not match expected configuration" -object $CurrentConfig -tenant $Tenant -standardName 'AutopilotProfile' -standardId $Settings.standardId
123-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' do not match expected configuration" -sev Info
124+
Write-StandardsAlert -message "Autopilot profile '$($DisplayName)' do not match expected configuration" -object $CurrentConfig -tenant $Tenant -standardName 'AutopilotProfile' -standardId $Settings.standardId
125+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' do not match expected configuration" -sev Info
124126
}
125127
}
126128
}

0 commit comments

Comments
 (0)