Skip to content

Commit 2cba09e

Browse files
authored
Merge pull request #535 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 3e2eea5 + 04ade59 commit 2cba09e

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

Modules/CIPPCore/Public/Get-CIPPTimerFunctions.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ function Get-CIPPTimerFunctions {
1010

1111
# Check running nodes
1212
$VersionTable = Get-CIPPTable -tablename 'Version'
13-
$Nodes = Get-CIPPAzDataTableEntity @VersionTable -Filter "PartitionKey eq 'Version' and RowKey ne 'Version'" | Where-Object { $_.RowKey -match '-' }
14-
$AvailableNodes = $Nodes.RowKey | ForEach-Object { ($_ -split '-')[1] }
13+
$Nodes = Get-CIPPAzDataTableEntity @VersionTable -Filter "PartitionKey eq 'Version' and RowKey ne 'Version'"
14+
1515
$FunctionName = $env:WEBSITE_SITE_NAME
16+
$MainFunctionVersion = ($Nodes | Where-Object { $_.RowKey -eq $FunctionName }).Version
17+
$AvailableNodes = $Nodes.RowKey | Where-Object { $_.RowKey -match '-' -and $_.Version -eq $MainFunctionVersion } | ForEach-Object { ($_ -split '-')[1] }
1618

1719
# Get node name
1820
if ($FunctionName -match '-') {
@@ -22,7 +24,7 @@ function Get-CIPPTimerFunctions {
2224
}
2325

2426
$RunOnProcessor = $true
25-
if ($Config -and $Config.state -eq $true) {
27+
if ($Config -and $Config.state -eq $true -and $AvailableNodes.Count -gt 0) {
2628
if ($env:CIPP_PROCESSOR -ne 'true') {
2729
$RunOnProcessor = $false
2830
}

Modules/CIPPCore/Public/Remove-CIPPGroupMember.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ function Remove-CIPPGroupMember(
77
[string]$APIName = 'Remove Group Member'
88
) {
99
try {
10-
if ($Member -like '*#EXT#*') { $Member = [System.Web.HttpUtility]::UrlEncode($Member) }
11-
# $MemberIDs = 'https://graph.microsoft.com/v1.0/directoryObjects/' + (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($Member)" -tenantid $TenantFilter).id
12-
# $AddMemberBody = "{ `"[email protected]`": $(ConvertTo-Json @($MemberIDs)) }"
1310
if ($GroupType -eq 'Distribution list' -or $GroupType -eq 'Mail-Enabled Security') {
1411
$Params = @{ Identity = $GroupId; Member = $Member; BypassSecurityGroupManagerCheck = $true }
1512
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Remove-DistributionGroupMember' -cmdParams $Params -UseSystemMailbox $true
1613
} else {
14+
if ($Member -match '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') {
15+
Write-Information "Member $Member is a GUID, proceeding with removal."
16+
} else {
17+
Write-Information "Member $Member is not a GUID, attempting to resolve to object ID."
18+
if ($Member -like '*#EXT#*') { $Member = [System.Web.HttpUtility]::UrlEncode($Member) }
19+
$UserObject = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($Member)?`$select=id" -tenantid $TenantFilter
20+
if ($null -eq $UserObject.id) {
21+
throw "Could not resolve user $Member to an object ID."
22+
}
23+
$Member = $UserObject.id
24+
Write-Information "Resolved member to object ID: $Member"
25+
}
1726
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupId)/members/$($Member)/`$ref" -tenantid $TenantFilter -type DELETE -body '{}' -Verbose
1827
}
1928
$Results = "Successfully removed user $($Member) from $($GroupId)."

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ function Invoke-CIPPStandardMalwareFilterPolicy {
7575

7676
try {
7777
$CurrentState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MalwareFilterPolicy' |
78-
Where-Object -Property Name -EQ $PolicyName |
79-
Select-Object Name, EnableFileFilter, FileTypeAction, FileTypes, ZapEnabled, QuarantineTag, EnableInternalSenderAdminNotifications, InternalSenderAdminAddress, EnableExternalSenderAdminNotifications, ExternalSenderAdminAddress
80-
}
81-
catch {
78+
Where-Object -Property Name -EQ $PolicyName |
79+
Select-Object Name, EnableFileFilter, FileTypeAction, FileTypes, ZapEnabled, QuarantineTag, EnableInternalSenderAdminNotifications, InternalSenderAdminAddress, EnableExternalSenderAdminNotifications, ExternalSenderAdminAddress
80+
} catch {
8281
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
8382
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the MalwareFilterPolicy state for $Tenant. Error: $ErrorMessage" -Sev Error
8483
return
@@ -92,27 +91,29 @@ function Invoke-CIPPStandardMalwareFilterPolicy {
9291
$ExpectedFileTypes = $DefaultFileTypes + @($Settings.OptionalFileTypes.Split(',').Trim())
9392
}
9493

94+
$FileTypeAction = $Settings.FileTypeAction.value ?? $Settings.FileTypeAction ?? 'Quarantine'
95+
9596
$StateIsCorrect = ($CurrentState.Name -eq $PolicyName) -and
96-
($CurrentState.EnableFileFilter -eq $true) -and
97-
($CurrentState.FileTypeAction -eq $Settings.FileTypeAction) -and
98-
(!(Compare-Object -ReferenceObject $CurrentState.FileTypes -DifferenceObject $ExpectedFileTypes)) -and
99-
($CurrentState.ZapEnabled -eq $true) -and
100-
($CurrentState.QuarantineTag -eq $Settings.QuarantineTag) -and
101-
($CurrentState.EnableInternalSenderAdminNotifications -eq $Settings.EnableInternalSenderAdminNotifications) -and
102-
(($null -eq $Settings.InternalSenderAdminAddress) -or ($CurrentState.InternalSenderAdminAddress -eq $Settings.InternalSenderAdminAddress)) -and
103-
($CurrentState.EnableExternalSenderAdminNotifications -eq $Settings.EnableExternalSenderAdminNotifications) -and
104-
(($null -eq $Settings.ExternalSenderAdminAddress) -or ($CurrentState.ExternalSenderAdminAddress -eq $Settings.ExternalSenderAdminAddress))
97+
($CurrentState.EnableFileFilter -eq $true) -and
98+
($CurrentState.FileTypeAction -eq $FileTypeAction) -and
99+
(!(Compare-Object -ReferenceObject $CurrentState.FileTypes -DifferenceObject $ExpectedFileTypes)) -and
100+
($CurrentState.ZapEnabled -eq $true) -and
101+
($CurrentState.QuarantineTag -eq $Settings.QuarantineTag) -and
102+
($CurrentState.EnableInternalSenderAdminNotifications -eq $Settings.EnableInternalSenderAdminNotifications) -and
103+
(($null -eq $Settings.InternalSenderAdminAddress) -or ($CurrentState.InternalSenderAdminAddress -eq $Settings.InternalSenderAdminAddress)) -and
104+
($CurrentState.EnableExternalSenderAdminNotifications -eq $Settings.EnableExternalSenderAdminNotifications) -and
105+
(($null -eq $Settings.ExternalSenderAdminAddress) -or ($CurrentState.ExternalSenderAdminAddress -eq $Settings.ExternalSenderAdminAddress))
105106

106107
$AcceptedDomains = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AcceptedDomain'
107108

108109
$RuleState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MalwareFilterRule' |
109-
Where-Object -Property Name -EQ $RuleName |
110-
Select-Object Name, MalwareFilterPolicy, Priority, RecipientDomainIs
110+
Where-Object -Property Name -EQ $RuleName |
111+
Select-Object Name, MalwareFilterPolicy, Priority, RecipientDomainIs
111112

112113
$RuleStateIsCorrect = ($RuleState.Name -eq $RuleName) -and
113-
($RuleState.MalwareFilterPolicy -eq $PolicyName) -and
114-
($RuleState.Priority -eq 0) -and
115-
(!(Compare-Object -ReferenceObject $RuleState.RecipientDomainIs -DifferenceObject $AcceptedDomains.Name))
114+
($RuleState.MalwareFilterPolicy -eq $PolicyName) -and
115+
($RuleState.Priority -eq 0) -and
116+
(!(Compare-Object -ReferenceObject $RuleState.RecipientDomainIs -DifferenceObject $AcceptedDomains.Name))
116117

117118
if ($Settings.remediate -eq $true) {
118119

@@ -122,7 +123,7 @@ function Invoke-CIPPStandardMalwareFilterPolicy {
122123
$cmdParams = @{
123124
EnableFileFilter = $true
124125
FileTypes = $ExpectedFileTypes
125-
FileTypeAction = $Settings.FileTypeAction
126+
FileTypeAction = $FileTypeAction
126127
ZapEnabled = $true
127128
QuarantineTag = $Settings.QuarantineTag
128129
EnableInternalSenderAdminNotifications = $Settings.EnableInternalSenderAdminNotifications

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ function Invoke-CIPPStandardSpoofWarn {
4444

4545
try {
4646
$CurrentInfo = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-ExternalInOutlook')
47-
}
48-
catch {
47+
} catch {
4948
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
5049
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the SpoofWarn state for $Tenant. Error: $ErrorMessage" -Sev Error
5150
return
5251
}
5352

5453
# Get state value using null-coalescing operator
5554
$state = $Settings.state.value ?? $Settings.state
55+
56+
$IsEnabled = $state -eq 'enabled'
5657
$AllowListAdd = $Settings.AllowListAdd.value ?? $Settings.AllowListAdd
5758

5859
# Test if all entries in the AllowListAdd variable are in the AllowList
@@ -131,7 +132,7 @@ function Invoke-CIPPStandardSpoofWarn {
131132
if ($Settings.report -eq $true) {
132133
Add-CIPPBPAField -FieldName 'SpoofingWarnings' -FieldValue $CurrentInfo.Enabled -StoreAs bool -Tenant $Tenant
133134

134-
if ($AllowListCorrect -eq $true -and $CurrentInfo.Enabled -eq $status) {
135+
if ($AllowListCorrect -eq $true -and $CurrentInfo.Enabled -eq $IsEnabled) {
135136
$FieldValue = $true
136137
} else {
137138
$FieldValue = $CurrentInfo | Select-Object Enabled, AllowList

0 commit comments

Comments
 (0)