Skip to content

Commit ea86e1f

Browse files
authored
Merge pull request #550 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 7c7d0a6 + 2ffa768 commit ea86e1f

28 files changed

+288
-103
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertAppleTerms.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertAppleTerms {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
@@ -18,13 +18,23 @@ function Get-CIPPAlertAppleTerms {
1818
# 4 = Warning
1919

2020
try {
21-
$appleterms = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/depOnboardingSettings" -tenantid $TenantFilter
21+
Write-Host "Checking Apple Terms for $($TenantFilter)"
22+
$AppleTerms = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/depOnboardingSettings' -tenantid $TenantFilter
2223
} catch {
2324
return
2425
}
2526

26-
if ($appleterms.lastSyncErrorCode -eq 3) {
27-
$AlertData = "New Apple Business Manager terms are ready to accept."
27+
if ($AppleTerms.lastSyncErrorCode -eq 3) {
28+
$AlertData = [PSCustomObject]@{
29+
Message = 'New Apple Business Manager terms are ready to accept.'
30+
AppleIdentifier = $AppleTerms.appleIdentifier
31+
TokenName = $AppleTerms.tokenName
32+
TokenExpirationDateTime = $AppleTerms.tokenExpirationDateTime
33+
LastSyncErrorCode = $AppleTerms.lastSyncErrorCode
34+
LastSuccessfulSyncDateTime = $AppleTerms.lastSuccessfulSyncDateTime
35+
LastSyncTriggeredDateTime = $AppleTerms.lastSyncTriggeredDateTime
36+
Tenant = $TenantFilter
37+
}
2838
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2939
}
3040
}

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertDefenderMalware.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ function Get-CIPPAlertDefenderMalware {
1414
try {
1515
$TenantId = (Get-Tenants | Where-Object -Property defaultDomainName -EQ $TenantFilter).customerId
1616
$AlertData = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/managedTenants/windowsDeviceMalwareStates?`$top=999&`$filter=tenantId eq '$($TenantId)'" | Where-Object { $_.malwareThreatState -eq 'Active' } | ForEach-Object {
17-
"$($_.managedDeviceName): Malware found and active. Severity: $($_.MalwareSeverity). Malware name: $($_.MalwareDisplayName)"
17+
[PSCustomObject]@{
18+
DeviceName = $_.managedDeviceName
19+
MalwareName = $_.malwareDisplayName
20+
MalwareSeverity = $_.malwareSeverity
21+
ThreatState = $_.malwareThreatState
22+
AdditionalInformationUrl = $_.additionalInformationUrl
23+
InitialDetectionDateTime = $_.initialDetectionDateTime
24+
LastStateChangeDateTime = $_.lastStateChangeDateTime
25+
DetectionCount = $_.detectionCount
26+
Tenant = $TenantFilter
27+
TenantId = $_.tenantId
28+
}
1829
}
1930
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2031

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertDefenderStatus.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ function Get-CIPPAlertDefenderStatus {
1313
try {
1414
$TenantId = (Get-Tenants | Where-Object -Property defaultDomainName -EQ $TenantFilter).customerId
1515
$AlertData = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/managedTenants/windowsProtectionStates?`$top=999&`$filter=tenantId eq '$($TenantId)'" | Where-Object { $_.realTimeProtectionEnabled -eq $false -or $_.MalwareprotectionEnabled -eq $false } | ForEach-Object {
16-
"$($_.managedDeviceName) - Real Time Protection: $($_.realTimeProtectionEnabled) & Malware Protection: $($_.MalwareprotectionEnabled)"
16+
[PSCustomObject]@{
17+
ManagedDeviceName = $_.managedDeviceName
18+
RealTimeProtectionEnabled = $_.realTimeProtectionEnabled
19+
MalwareProtectionEnabled = $_.malwareProtectionEnabled
20+
NetworkInspectionSystemEnabled = $_.networkInspectionSystemEnabled
21+
ManagedDeviceHealthState = $_.managedDeviceHealthState
22+
AttentionRequired = $_.attentionRequired
23+
LastSyncDateTime = $_.lastSyncDateTime
24+
OsVersion = $_.osVersion
25+
Tenant = $TenantFilter
26+
TenantId = $_.tenantId
27+
}
1728
}
1829
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
1930

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertExpiringLicenses.ps1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@ function Get-CIPPAlertExpiringLicenses {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
1111
$TenantFilter
1212
)
1313
try {
1414
$AlertData = Get-CIPPLicenseOverview -TenantFilter $TenantFilter | ForEach-Object {
15-
$timeTorenew = [int64]$_.TimeUntilRenew
16-
if ($timeTorenew -lt 30 -and $_.TimeUntilRenew -gt 0) {
17-
Write-Host "$($_.License) will expire in $($_.TimeUntilRenew) days. The estimated term is $($_.EstTerm)"
18-
"$($_.License) will expire in $($_.TimeUntilRenew) days. The estimated term is $($_.EstTerm)"
15+
$TermData = $_.TermInfo | ConvertFrom-Json
16+
foreach ($Term in $TermData) {
17+
if ($Term.DaysUntilRenew -lt 30 -and $Term.DaysUntilRenew -gt 0) {
18+
Write-Host "$($_.License) will expire in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
19+
[PSCustomObject]@{
20+
Message = "$($_.License) will expire in $($Term.DaysUntilRenew) days. The estimated term is $($Term.Term)"
21+
License = $_.License
22+
SkuId = $_.skuId
23+
DaysUntilRenew = $Term.DaysUntilRenew
24+
Term = $Term.Term
25+
Status = $Term.Status
26+
TotalLicenses = $Term.TotalLicenses
27+
CountUsed = $_.CountUsed
28+
NextLifecycle = $Term.NextLifecycle
29+
Tenant = $_.Tenant
30+
}
31+
}
1932
}
20-
2133
}
2234
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2335

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertGlobalAdminNoAltEmail.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertGlobalAdminNoAltEmail {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
@@ -22,7 +22,14 @@ function Get-CIPPAlertGlobalAdminNoAltEmail {
2222
}
2323

2424
if ($adminsWithoutAltEmail.Count -gt 0) {
25-
$AlertData = "The following Global Admin accounts do not have an alternate email address set: $($adminsWithoutAltEmail.userPrincipalName -join ', ')"
25+
$AlertData = foreach ($admin in $adminsWithoutAltEmail) {
26+
[PSCustomObject]@{
27+
DisplayName = $admin.displayName
28+
UserPrincipalName = $admin.userPrincipalName
29+
Id = $admin.id
30+
Tenant = $TenantFilter
31+
}
32+
}
2633
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2734
}
2835
} catch {

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertHuntressRogueApps.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Get-CIPPAlertHuntressRogueApps {
1010
https://huntresslabs.github.io/rogueapps/
1111
#>
1212
[CmdletBinding()]
13-
Param (
13+
param (
1414
[Parameter(Mandatory = $false)]
1515
[Alias('input')]
1616
$InputValue,

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertInactiveLicensedUsers.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertInactiveLicensedUsers {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
@@ -18,7 +18,7 @@ function Get-CIPPAlertInactiveLicensedUsers {
1818
$Lookup = (Get-Date).AddDays(-90).ToUniversalTime()
1919

2020
# Build base filter - cannot filter assignedLicenses server-side
21-
$BaseFilter = if ($InputValue -eq $true) { "accountEnabled eq true" } else { "" }
21+
$BaseFilter = if ($InputValue -eq $true) { 'accountEnabled eq true' } else { '' }
2222

2323
$Uri = if ($BaseFilter) {
2424
"https://graph.microsoft.com/beta/users?`$filter=$BaseFilter&`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled,assignedLicenses"
@@ -56,7 +56,13 @@ function Get-CIPPAlertInactiveLicensedUsers {
5656
$Message = 'User {0} has been inactive for {1} days but still has a license assigned. Last sign-in: {2}' -f $user.UserPrincipalName, $daysSinceSignIn, $lastSignIn
5757
}
5858

59-
$user | Select-Object -Property UserPrincipalName, signInActivity, @{Name = 'Message'; Expression = { $Message } }
59+
[PSCustomObject]@{
60+
UserPrincipalName = $user.UserPrincipalName
61+
Id = $user.id
62+
lastSignIn = $lastSignIn
63+
Message = $Message
64+
Tenant = $TenantFilter
65+
}
6066
}
6167
}
6268

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertLicenseAssignmentErrors.ps1

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertLicenseAssignmentErrors {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory)]
99
$TenantFilter,
1010
[Alias('input')]
@@ -14,24 +14,24 @@ function Get-CIPPAlertLicenseAssignmentErrors {
1414
# Define error code translations for human-readable messages
1515
$ErrorTranslations = @(
1616
@{
17-
ErrorCode = "CountViolation"
18-
Description = "Not enough licenses available - the organization has exceeded the number of available licenses for this SKU"
17+
ErrorCode = 'CountViolation'
18+
Description = 'Not enough licenses available - the organization has exceeded the number of available licenses for this SKU'
1919
},
2020
@{
21-
ErrorCode = "MutuallyExclusiveViolation"
22-
Description = "Conflicting licenses assigned - this license cannot be assigned alongside another license the user already has"
21+
ErrorCode = 'MutuallyExclusiveViolation'
22+
Description = 'Conflicting licenses assigned - this license cannot be assigned alongside another license the user already has'
2323
},
2424
@{
25-
ErrorCode = "ProhibitedInUsageLocationViolation"
25+
ErrorCode = 'ProhibitedInUsageLocationViolation'
2626
Description = "License not available in user's location - this license cannot be assigned to users in the user's current usage location"
2727
},
2828
@{
29-
ErrorCode = "UniquenessViolation"
30-
Description = "Duplicate license assignment - this license can only be assigned once per user"
29+
ErrorCode = 'UniquenessViolation'
30+
Description = 'Duplicate license assignment - this license can only be assigned once per user'
3131
},
3232
@{
33-
ErrorCode = "Unknown"
34-
Description = "Unknown license assignment error - an unspecified error occurred during license assignment"
33+
ErrorCode = 'Unknown'
34+
Description = 'Unknown license assignment error - an unspecified error occurred during license assignment'
3535
}
3636
)
3737

@@ -44,11 +44,11 @@ function Get-CIPPAlertLicenseAssignmentErrors {
4444
$_.licenseAssignmentStates -and
4545
($_.licenseAssignmentStates | Where-Object {
4646
$_.error -and (
47-
$_.error -like "*CountViolation*" -or
48-
$_.error -like "*MutuallyExclusiveViolation*" -or
49-
$_.error -like "*ProhibitedInUsageLocationViolation*" -or
50-
$_.error -like "*UniquenessViolation*" -or
51-
$_.error -like "*Unknown*"
47+
$_.error -like '*CountViolation*' -or
48+
$_.error -like '*MutuallyExclusiveViolation*' -or
49+
$_.error -like '*ProhibitedInUsageLocationViolation*' -or
50+
$_.error -like '*UniquenessViolation*' -or
51+
$_.error -like '*Unknown*'
5252
)
5353
})
5454
}
@@ -57,11 +57,11 @@ function Get-CIPPAlertLicenseAssignmentErrors {
5757
$LicenseAssignmentErrors = foreach ($User in $UsersWithViolations) {
5858
$ViolationErrors = $User.licenseAssignmentStates | Where-Object {
5959
$_.error -and (
60-
$_.error -like "*CountViolation*" -or
61-
$_.error -like "*MutuallyExclusiveViolation*" -or
62-
$_.error -like "*ProhibitedInUsageLocationViolation*" -or
63-
$_.error -like "*UniquenessViolation*" -or
64-
$_.error -like "*Unknown*"
60+
$_.error -like '*CountViolation*' -or
61+
$_.error -like '*MutuallyExclusiveViolation*' -or
62+
$_.error -like '*ProhibitedInUsageLocationViolation*' -or
63+
$_.error -like '*UniquenessViolation*' -or
64+
$_.error -like '*Unknown*'
6565
)
6666
}
6767

@@ -74,9 +74,19 @@ function Get-CIPPAlertLicenseAssignmentErrors {
7474
"Unknown license assignment error: $($Violation.error)"
7575
}
7676

77-
$PrettyName = Convert-SKUname -skuID $Violation.skuId
77+
$PrettyName = Convert-SKUname -SkuID $Violation.skuId
7878

79-
"$($User.userPrincipalName): $HumanReadableError (License: $PrettyName)"
79+
$Message = "$($User.userPrincipalName): $HumanReadableError (License: $PrettyName)"
80+
[PSCustomObject]@{
81+
Message = $Message
82+
UserPrincipalName = $User.userPrincipalName
83+
Error = $HumanReadableError
84+
LicenseName = $PrettyName
85+
SkuId = $Violation.skuId
86+
DisplayName = $User.displayName
87+
Id = $User.id
88+
Tenant = $TenantFilter
89+
}
8090
}
8191
}
8292

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertLowDomainScore.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertLowDomainScore {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory)]
99
$TenantFilter,
1010
[Alias('input')]
@@ -13,10 +13,14 @@ function Get-CIPPAlertLowDomainScore {
1313
)
1414

1515
$DomainData = Get-CIPPDomainAnalyser -TenantFilter $TenantFilter
16-
$LowScoreDomains = $DomainData | Where-Object {
17-
$_.ScorePercentage -lt $InputValue -and $_.ScorePercentage -ne ''
18-
} | ForEach-Object {
19-
"$($_.Domain): Domain security score is $($_.ScorePercentage)%, which is below the threshold of $InputValue%. Issues: $($_.ScoreExplanation)"
16+
$LowScoreDomains = $DomainData | Where-Object { $_.ScorePercentage -lt $InputValue -and $_.ScorePercentage -ne '' } | ForEach-Object {
17+
[PSCustomObject]@{
18+
Message = "$($_.Domain): Domain security score is $($_.ScorePercentage)%, which is below the threshold of $InputValue%. Issues: $($_.ScoreExplanation)"
19+
Domain = $_.Domain
20+
ScorePercentage = $_.ScorePercentage
21+
ScoreExplanation = $_.ScoreExplanation
22+
Tenant = $TenantFilter
23+
}
2024
}
2125

2226
if ($LowScoreDomains) {

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertMFAAdmins.ps1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertMFAAdmins {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
@@ -18,9 +18,20 @@ function Get-CIPPAlertMFAAdmins {
1818
}
1919
}
2020
if (!$DuoActive) {
21-
$users = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails?`$top=999&filter=IsAdmin eq true and isMfaRegistered eq false and userType eq 'member'&`$select=userDisplayName,userPrincipalName,lastUpdatedDateTime,isMfaRegistered,IsAdmin" -tenantid $($TenantFilter) -AsApp $true | Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' }
22-
if ($users.UserPrincipalName) {
23-
$AlertData = "The following admins do not have MFA registered: $($users.UserPrincipalName -join ', ')"
21+
$Users = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails?`$top=999&filter=IsAdmin eq true and isMfaRegistered eq false and userType eq 'member'&`$select=id,userDisplayName,userPrincipalName,lastUpdatedDateTime,isMfaRegistered,IsAdmin" -tenantid $($TenantFilter) -AsApp $true |
22+
Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' }
23+
if ($Users.UserPrincipalName) {
24+
$AlertData = foreach ($user in $Users) {
25+
[PSCustomObject]@{
26+
Message = "Admin user $($user.userDisplayName) ($($user.userPrincipalName)) does not have MFA registered."
27+
UserPrincipalName = $user.userPrincipalName
28+
DisplayName = $user.userDisplayName
29+
Id = $user.id
30+
LastUpdated = $user.lastUpdatedDateTime
31+
Tenant = $TenantFilter
32+
}
33+
}
34+
2435
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2536

2637
}

0 commit comments

Comments
 (0)