Skip to content

Commit c088057

Browse files
Merge pull request #617 from KelvinTegelaar/dev
Dev
2 parents d1f3e07 + 0e16005 commit c088057

File tree

5 files changed

+129
-44
lines changed

5 files changed

+129
-44
lines changed

Durable_BECRun/run.ps1

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@ param($Context)
22
#$Context does not allow itself to be cast to a pscustomobject for some reason, so we convert
33
$context = $Context | ConvertTo-Json | ConvertFrom-Json
44
$APIName = $TriggerMetadata.FunctionName
5-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
5+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
66
$TenantFilter = $Context.input.tenantfilter
77
$SuspectUser = $Context.input.userid
88
$UserName = $Context.input.username
99
Write-Host "Working on $UserName"
1010
try {
1111
$startDate = (Get-Date).AddDays(-7)
1212
$endDate = (Get-Date)
13-
$auditLog = (New-ExoRequest -tenantid $Tenantfilter -cmdlet "Get-AdminAuditLogConfig").UnifiedAuditLogIngestionEnabled
13+
$auditLog = (New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-AdminAuditLogConfig').UnifiedAuditLogIngestionEnabled
1414
$7dayslog = if ($auditLog -eq $false) {
15-
$ExtractResult = "AuditLog is disabled. Cannot perform full analysis"
16-
}
17-
else {
15+
$ExtractResult = 'AuditLog is disabled. Cannot perform full analysis'
16+
} else {
1817
$sessionid = Get-Random -Minimum 10000 -Maximum 99999
1918
$operations = @(
20-
"New-InboxRule",
21-
"Set-InboxRule",
22-
"UpdateInboxRules",
23-
"Remove-MailboxPermission",
24-
"Add-MailboxPermission",
25-
"UpdateCalendarDelegation",
26-
"AddFolderPermissions",
27-
"MailboxLogin",
28-
"UserLoggedIn"
19+
'New-InboxRule',
20+
'Set-InboxRule',
21+
'UpdateInboxRules',
22+
'Remove-MailboxPermission',
23+
'Add-MailboxPermission',
24+
'UpdateCalendarDelegation',
25+
'AddFolderPermissions',
26+
'MailboxLogin',
27+
'UserLoggedIn'
2928
)
3029
$startDate = (Get-Date).AddDays(-7)
3130
$endDate = (Get-Date)
3231
$SearchParam = @{
33-
SessionCommand = "ReturnLargeSet"
32+
SessionCommand = 'ReturnLargeSet'
3433
Operations = $operations
3534
sessionid = $sessionid
3635
startDate = $startDate
3736
endDate = $endDate
3837
}
3938
do {
40-
New-ExoRequest -tenantid $Tenantfilter -cmdlet "Search-unifiedAuditLog" -cmdParams $SearchParam -Anchor $Username
39+
New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Search-unifiedAuditLog' -cmdParams $SearchParam -Anchor $Username
4140
Write-Host "Retrieved $($logsTenant.count) logs" -ForegroundColor Yellow
4241
$logsTenant
4342
} while ($LogsTenant.count % 5000 -eq 0 -and $LogsTenant.count -ne 0)
44-
$ExtractResult = "Succesfully extracted logs from auditlog"
43+
$ExtractResult = 'Succesfully extracted logs from auditlog'
4544
}
4645
Try {
4746
$URI = "https://graph.microsoft.com/beta/auditLogs/signIns?`$filter=(userId eq '$SuspectUser')&`$top=1&`$orderby=createdDateTime desc"
@@ -50,29 +49,26 @@ try {
5049
@{ Name = 'AppDisplayName'; Expression = { $_.resourceDisplayName } },
5150
@{ Name = 'Status'; Expression = { if (($_.conditionalAccessStatus -eq 'Success' -or 'Not Applied') -and $_.status.errorCode -eq 0) { 'Success' } else { 'Failed' } } },
5251
@{ Name = 'IPAddress'; Expression = { $_.ipAddress } }
53-
}
54-
catch {
52+
} catch {
5553
$LastSignIn = [PSCustomObject]@{
56-
AppDisplayName = "Unknown - could not retrieve information. No access to sign-in logs"
57-
CreatedDateTime = "Unknown"
58-
Id = "0"
59-
Status = "Could not retrieve additional details"
54+
AppDisplayName = 'Unknown - could not retrieve information. No access to sign-in logs'
55+
CreatedDateTime = 'Unknown'
56+
Id = '0'
57+
Status = 'Could not retrieve additional details'
6058
}
6159
}
6260
#List all users devices
6361
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($SuspectUser)
6462
$base64IdentityParam = [Convert]::ToBase64String($Bytes)
6563
Try {
6664
$Devices = New-GraphGetRequest -uri "https://outlook.office365.com:443/adminapi/beta/$($TenantFilter)/mailbox('$($base64IdentityParam)')/MobileDevice/Exchange.GetMobileDeviceStatistics()/?IsEncoded=True" -Tenantid $tenantfilter -scope ExchangeOnline
67-
}
68-
catch {
65+
} catch {
6966
$Devices = $null
7067
}
71-
$PermissionsLog = ($7dayslog | Where-Object -Property Operations -In "Remove-MailboxPermission", "Add-MailboxPermission", "UpdateCalendarDelegation", "AddFolderPermissions" ).AuditData | ConvertFrom-Json -Depth 100 | ForEach-Object {
68+
$PermissionsLog = ($7dayslog | Where-Object -Property Operations -In 'Remove-MailboxPermission', 'Add-MailboxPermission', 'UpdateCalendarDelegation', 'AddFolderPermissions' ).AuditData | ConvertFrom-Json -Depth 100 | ForEach-Object {
7269
$perms = if ($_.Parameters) {
73-
$_.Parameters | ForEach-Object { if ($_.Name -eq "AccessRights") { $_.Value } }
74-
}
75-
else
70+
$_.Parameters | ForEach-Object { if ($_.Name -eq 'AccessRights') { $_.Value } }
71+
} else
7672
{ $_.item.ParentFolder.MemberRights }
7773
$objectID = if ($_.ObjectID) { $_.ObjectID } else { $($_.MailboxOwnerUPN) + $_.item.ParentFolder.Path }
7874
[pscustomobject]@{
@@ -83,43 +79,42 @@ try {
8379
}
8480
}
8581

86-
$RulesLog = @(($7dayslog | Where-Object -Property Operations -In "New-InboxRule", "Set-InboxRule", "UpdateInboxRules").AuditData | ConvertFrom-Json) | ForEach-Object {
82+
$RulesLog = @(($7dayslog | Where-Object -Property Operations -In 'New-InboxRule', 'Set-InboxRule', 'UpdateInboxRules').AuditData | ConvertFrom-Json) | ForEach-Object {
8783
Write-Host ($_ | ConvertTo-Json)
8884
[pscustomobject]@{
8985
ClientIP = $_.ClientIP
9086
CreationTime = $_.CreationTime
9187
UserId = $_.UserId
92-
RuleName = ($_.OperationProperties | ForEach-Object { if ($_.Name -eq "RuleName") { $_.Value } })
93-
RuleCondition = ($_.OperationProperties | ForEach-Object { if ($_.Name -eq "RuleCondition") { $_.Value } })
88+
RuleName = ($_.OperationProperties | ForEach-Object { if ($_.Name -eq 'RuleName') { $_.Value } })
89+
RuleCondition = ($_.OperationProperties | ForEach-Object { if ($_.Name -eq 'RuleCondition') { $_.Value } })
9490
}
9591
}
9692
$PasswordChanges = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`select=lastPasswordChangeDateTime,displayname,UserPrincipalName" -Tenantid $tenantfilter | Where-Object { $_.lastPasswordChangeDateTime -gt $startDate }
97-
$NewUsers = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users?`$select=displayname,UserPrincipalName,CreatedDateTime" -Tenantid $tenantfilter | Where-Object { $_.CreatedDateTime -gt $startDate }
93+
$NewUsers = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users?`$select=displayname,UserPrincipalName,CreatedDateTime" -Tenantid $tenantfilter | Where-Object { $_.CreatedDateTime -gt $startDate }
9894
$MFADevices = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($SuspectUser)/authentication/methods" -Tenantid $tenantfilter
9995
$NewSPs = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/servicePrincipals?`$select=displayName,createdDateTime,id,AppDisplayName&`$filter=createdDateTime ge $($startDate.ToString('yyyy-MM-ddTHH:mm:ssZ'))" -Tenantid $tenantfilter
100-
$Last50Logons = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/auditLogs/signIns?`$top=50&`$orderby=createdDateTime desc" -tenantid $TenantFilter -noPagination $true -verbose | Select-Object @{ Name = 'CreatedDateTime'; Expression = { $(($_.createdDateTime | Out-String) -replace '\r\n') } },
96+
$Last50Logons = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/auditLogs/signIns?`$top=50&`$orderby=createdDateTime desc" -tenantid $TenantFilter -noPagination $true -verbose | Select-Object @{ Name = 'CreatedDateTime'; Expression = { $(($_.createdDateTime | Out-String) -replace '\r\n') } },
10197
id,
10298
@{ Name = 'AppDisplayName'; Expression = { $_.resourceDisplayName } },
10399
@{ Name = 'Status'; Expression = { if (($_.conditionalAccessStatus -eq 'Success' -or 'Not Applied') -and $_.status.errorCode -eq 0) { 'Success' } else { 'Failed' } } },
104100
@{ Name = 'IPAddress'; Expression = { $_.ipAddress } }, UserPrincipalName
105101
$Results = [PSCustomObject]@{
106-
AddedApps = $NewSPs
107-
SuspectUserMailboxLogons = $Last50Logons
102+
AddedApps = @($NewSPs)
103+
SuspectUserMailboxLogons = @($Last50Logons)
108104
LastSuspectUserLogon = @($LastSignIn)
109105
SuspectUserDevices = @($Devices)
110106
NewRules = @($RulesLog)
111107
MailboxPermissionChanges = @($PermissionsLog)
112108
NewUsers = @($NewUsers)
113-
MFADevices = $MFADevices
114-
ChangedPasswords = $PasswordChanges
109+
MFADevices = @($MFADevices)
110+
ChangedPasswords = @($PasswordChanges)
115111
ExtractedAt = (Get-Date).ToString('s')
116112
ExtractResult = $ExtractResult
117113
}
118114

119-
}
120-
catch {
115+
} catch {
121116
$errMessage = Get-NormalizedError -message $_.Exception.Message
122-
$results = [pscustomobject]@{"Results" = "$errMessage" }
117+
$results = [pscustomobject]@{'Results' = "$errMessage" }
123118
}
124119

125120
$Table = Get-CippTable -tablename 'cachebec'
@@ -128,5 +123,5 @@ Add-CIPPAzDataTableEntity @Table -Entity @{
128123
UserId = $Context.input.userid
129124
Results = "$($results | ConvertTo-Json -Depth 10)"
130125
RowKey = $Context.input.userid
131-
PartitionKey = "bec"
126+
PartitionKey = 'bec'
132127
}

Modules/CIPPCore/Public/Remove-CIPPGroupMember.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function Remove-CIPPGroupMember(
1919
$Message = "Successfully removed user $($Member) from $GroupId."
2020
Write-LogMessage -user $ExecutingUser -API $APIName -tenant $TenantFilter -message $Message -Sev 'Info'
2121
return $message
22-
return
2322
} catch {
2423
$message = "Failed to remove user $($Member) from $($GroupId): $($_.Exception.Message)"
2524
Write-LogMessage -user $ExecutingUser -API $APIName -tenant $TenantFilter -message $message -Sev 'error'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
function Invoke-CIPPStandardDisableOutlookAddins {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
#>
6+
param($Tenant, $Settings)
7+
8+
$CurrentInfo = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-RoleAssignmentPolicy' | Where-Object { $_.IsDefault -eq $true }
9+
$Roles = @('My Custom Apps', 'My Marketplace Apps', 'My ReadWriteMailbox Apps')
10+
$RolesToRemove = foreach ($Role in $Roles) {
11+
if ($CurrentInfo.AssignedRoles -contains $Role) {
12+
$Role
13+
}
14+
}
15+
16+
if ($Settings.remediate) {
17+
if ($RolesToRemove) {
18+
$Errors = [System.Collections.Generic.List[string]]::new()
19+
20+
foreach ($Role in $RolesToRemove) {
21+
try {
22+
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-ManagementRoleAssignment' -cmdparams @{ RoleAssignee = $CurrentInfo.Identity; Role = $Role } | ForEach-Object {
23+
New-ExoRequest -tenantid $Tenant -cmdlet 'Remove-ManagementRoleAssignment' -cmdparams @{ Identity = $_.Guid; Confirm = $false } -UseSystemMailbox $true
24+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Disabled Outlook add-in role: $Role" -sev Debug
25+
}
26+
} catch {
27+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable Outlook add-in role: $Role Error: $($_.exception.message)" -sev Error
28+
$Errors.Add($Role)
29+
}
30+
}
31+
32+
if ($Errors.Count -gt 0) {
33+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable users from installing Outlook add-ins. Roles: $($Errors -join ', ')" -sev Error
34+
} else {
35+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Disabled users from installing Outlook add-ins. Roles removed: $($RolesToRemove -join ', ')" -sev Info
36+
$RolesToRemove = $null
37+
}
38+
} else {
39+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users installing Outlook add-ins already disabled' -sev Info
40+
}
41+
}
42+
43+
if ($Settings.alert) {
44+
if ($RolesToRemove) {
45+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are not disabled from installing Outlook add-ins.' -sev Alert
46+
} else {
47+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are disabled from installing Outlook add-ins.' -sev Info
48+
}
49+
}
50+
if ($Settings.report) {
51+
if ($RolesToRemove) { $State = $false } else { $State = $true }
52+
Add-CIPPBPAField -FieldName 'DisabledOutlookAddins' -FieldValue [bool]$State -StoreAs bool -Tenant $tenant
53+
}
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Invoke-CIPPStandardDisableSharePointLegacyAuth {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
#>
6+
param($Tenant, $Settings)
7+
8+
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/admin/sharepoint/settings?$select=isLegacyAuthProtocolsEnabled' -tenantid $Tenant -AsApp $true
9+
10+
If ($Settings.remediate) {
11+
12+
if ($CurrentInfo.isLegacyAuthProtocolsEnabled) {
13+
try {
14+
$body = '{"isLegacyAuthProtocolsEnabled": "false"}'
15+
$null = New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/admin/sharepoint/settings' -AsApp $true -Type patch -Body $body -ContentType 'application/json'
16+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Disabled SharePoint basic authentication' -sev Info
17+
$CurrentInfo.isLegacyAuthProtocolsEnabled = $false
18+
} catch {
19+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable SharePoint basic authentication. Error: $($_.exception.message)" -sev Error
20+
}
21+
} else {
22+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SharePoint basic authentication is already disabled' -sev Info
23+
}
24+
}
25+
if ($Settings.alert) {
26+
27+
if ($CurrentInfo.isLegacyAuthProtocolsEnabled) {
28+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SharePoint basic authentication is enabled' -sev Alert
29+
} else {
30+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SharePoint basic authentication is disabled' -sev Info
31+
}
32+
}
33+
if ($Settings.report) {
34+
35+
Add-CIPPBPAField -FieldName 'SharePointLegacyAuthEnabled' -FieldValue [bool]$CurrentInfo.isLegacyAuthProtocolsEnabled -StoreAs bool -Tenant $tenant
36+
}
37+
}

version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.0
1+
5.1.1

0 commit comments

Comments
 (0)