@@ -35,25 +35,29 @@ function Invoke-CIPPStandardlaps {
3535 try {
3636 $PreviousSetting = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' - tenantid $Tenant
3737 } catch {
38- $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
39- Write-LogMessage - API ' Standards' - Tenant $Tenant - Message " Could not get the DeviceRegistrationPolicy state for $Tenant . Error: $ErrorMessage " - Sev Error
38+ $ErrorMessage = Get-CippException - Exception $_
39+ Write-LogMessage - API ' Standards' - Tenant $Tenant - Message " Could not get the DeviceRegistrationPolicy state for $Tenant . Error: $ ( $ ErrorMessage.NormalizedError ) " - Sev Error - LogData $ErrorMessage
4040 return
4141 }
4242
4343 if ($Settings.remediate -eq $true ) {
44- try {
45- $PreviousSetting.localAdminPassword.isEnabled = $true
46- $NewBody = ConvertTo-Json - Compress - InputObject $PreviousSetting - Depth 10
47- New-GraphPostRequest - tenantid $Tenant - Uri ' https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' - Type PUT - Body $NewBody - ContentType ' application/json'
48- Write-LogMessage - API ' Standards' - tenant $Tenant - message ' LAPS has been enabled.' - sev Info
49- } catch {
50- $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
51- $PreviousSetting.localAdminPassword.isEnabled = $false
52- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Failed to enable LAPS: $ErrorMessage " - sev Error
44+ if ($PreviousSetting.localAdminPassword.isEnabled -eq $true ) {
45+ Write-LogMessage - API ' Standards' - tenant $Tenant - message ' LAPS is already enabled.' - sev Info
46+ } else {
47+ try {
48+ $PreviousSetting.localAdminPassword.isEnabled = $true
49+ $NewBody = ConvertTo-Json - Compress - InputObject $PreviousSetting - Depth 10
50+ New-GraphPostRequest - tenantid $Tenant - Uri ' https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' - Type PUT - Body $NewBody
51+ Write-LogMessage - API ' Standards' - tenant $Tenant - message ' LAPS has been enabled.' - sev Info
52+ } catch {
53+ $ErrorMessage = Get-CippException - Exception $_
54+ $PreviousSetting.localAdminPassword.isEnabled = $false
55+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Failed to enable LAPS: $ ( $ErrorMessage.NormalizedError ) " - sev Error - LogData $ErrorMessage
56+ }
5357 }
5458 }
5559 if ($Settings.alert -eq $true ) {
56- if ($PreviousSetting.localAdminPassword.isEnabled ) {
60+ if ($PreviousSetting.localAdminPassword.isEnabled -eq $true ) {
5761 Write-LogMessage - API ' Standards' - tenant $Tenant - message ' LAPS is enabled.' - sev Info
5862 } else {
5963 Write-StandardsAlert - message ' LAPS is not enabled' - object $PreviousSetting - tenant $Tenant - standardName ' laps' - standardId $Settings.standardId
0 commit comments