Skip to content

Commit c911fe9

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents ee77396 + 097614d commit c911fe9

6 files changed

+64
-38
lines changed

Modules/CIPPCore/Public/Invoke-CIPPOffboardingJob.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Invoke-CIPPOffboardingJob {
5858
}
5959
}
6060
{ $_.'RemoveLicenses' -eq 'true' } {
61-
Remove-CIPPLicense -userid $userid -username $Username -tenantFilter $Tenantfilter -ExecutingUser $ExecutingUser -APIName $APIName
61+
Remove-CIPPLicense -userid $userid -username $Username -tenantFilter $Tenantfilter -ExecutingUser $ExecutingUser -APIName $APIName -Schedule
6262
}
6363

6464
{ $_.'Deleteuser' -eq 'true' } {

Modules/CIPPCore/Public/Remove-CIPPLicense.ps1

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,57 @@ function Remove-CIPPLicense {
55
$userid,
66
$username,
77
$APIName = 'Remove License',
8-
$TenantFilter
8+
$TenantFilter,
9+
[switch]$Schedule
910
)
1011

11-
try {
12-
$ConvertTable = Import-Csv ConversionTable.csv
13-
$User = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($userid)" -tenantid $tenantFilter
14-
if (!$username) { $username = $User.userPrincipalName }
15-
$CurrentLicenses = $User.assignedlicenses.skuid
16-
$ConvertedLicense = $(($ConvertTable | Where-Object { $_.guid -in $CurrentLicenses }).'Product_Display_Name' | Sort-Object -Unique) -join ', '
17-
if ($CurrentLicenses) {
18-
$LicensePayload = [PSCustomObject]@{
19-
addLicenses = @()
20-
removeLicenses = @($CurrentLicenses)
12+
if ($Schedule.IsPresent) {
13+
$ScheduledTask = @{
14+
TenantFilter = $TenantFilter
15+
Name = "Remove License: $Username"
16+
Command = @{
17+
value = 'Remove-CIPPLicense'
2118
}
22-
if ($PSCmdlet.ShouldProcess($userid, "Remove licenses: $ConvertedLicense")) {
23-
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userid)/assignlicense" -tenantid $tenantFilter -type POST -body (ConvertTo-Json -InputObject $LicensePayload -Compress -Depth 5) -verbose
24-
Write-LogMessage -user $ExecutingUser -API $APIName -message "Removed licenses for $($username): $ConvertedLicense" -Sev 'Info' -tenant $TenantFilter
19+
Parameters = [pscustomobject]@{
20+
userid = $userid
21+
username = $username
22+
APIName = 'Scheduled License Removal'
23+
ExecutingUser = $ExecutingUser
2524
}
26-
return "Removed licenses for $($Username): $ConvertedLicense"
27-
} else {
28-
Write-LogMessage -user $ExecutingUser -API $APIName -message "No licenses to remove for $username" -Sev 'Info' -tenant $TenantFilter
29-
return "No licenses to remove for $username"
25+
ScheduledTime = [int64](([datetime]::UtcNow).AddMinutes(5) - (Get-Date '1/1/1970')).TotalSeconds
26+
PostExecution = @{
27+
Webhook = $false
28+
Email = $false
29+
PSA = $false
30+
}
31+
}
32+
Add-CIPPScheduledTask -Task $ScheduledTask -hidden $false
33+
return "Scheduled license removal for $username"
34+
} else {
35+
try {
36+
$ConvertTable = Import-Csv ConversionTable.csv
37+
$User = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($userid)" -tenantid $tenantFilter
38+
if (!$username) { $username = $User.userPrincipalName }
39+
$CurrentLicenses = $User.assignedlicenses.skuid
40+
$ConvertedLicense = $(($ConvertTable | Where-Object { $_.guid -in $CurrentLicenses }).'Product_Display_Name' | Sort-Object -Unique) -join ', '
41+
if ($CurrentLicenses) {
42+
$LicensePayload = [PSCustomObject]@{
43+
addLicenses = @()
44+
removeLicenses = @($CurrentLicenses)
45+
}
46+
if ($PSCmdlet.ShouldProcess($userid, "Remove licenses: $ConvertedLicense")) {
47+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userid)/assignlicense" -tenantid $tenantFilter -type POST -body (ConvertTo-Json -InputObject $LicensePayload -Compress -Depth 5) -verbose
48+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Removed licenses for $($username): $ConvertedLicense" -Sev 'Info' -tenant $TenantFilter
49+
}
50+
return "Removed licenses for $($Username): $ConvertedLicense"
51+
} else {
52+
Write-LogMessage -user $ExecutingUser -API $APIName -message "No licenses to remove for $username" -Sev 'Info' -tenant $TenantFilter
53+
return "No licenses to remove for $username"
54+
}
55+
} catch {
56+
$ErrorMessage = Get-CippException -Exception $_
57+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not remove license for $username. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
58+
return "Could not remove license for $($username). Error: $($ErrorMessage.NormalizedError)"
3059
}
31-
} catch {
32-
$ErrorMessage = Get-CippException -Exception $_
33-
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not remove license for $username. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
34-
return "Could not remove license for $($username). Error: $($ErrorMessage.NormalizedError)"
3560
}
3661
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function Invoke-CIPPStandardAntiPhishPolicy {
5151
param($Tenant, $Settings)
5252
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'AntiPhishPolicy'
5353

54-
$PolicyName = 'Default Anti-Phishing Policy'
54+
$PolicyName = @('Default Anti-Phishing Policy', 'Office365 AntiPhish Default (Default)')
5555

5656
$CurrentState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AntiPhishPolicy' |
57-
Where-Object -Property Name -EQ $PolicyName |
58-
Select-Object Name, Enabled, PhishThresholdLevel, EnableMailboxIntelligence, EnableMailboxIntelligenceProtection, EnableSpoofIntelligence, EnableFirstContactSafetyTips, EnableSimilarUsersSafetyTips, EnableSimilarDomainsSafetyTips, EnableUnusualCharactersSafetyTips, EnableUnauthenticatedSender, EnableViaTag, AuthenticationFailAction, SpoofQuarantineTag, MailboxIntelligenceProtectionAction, MailboxIntelligenceQuarantineTag, TargetedUserProtectionAction, TargetedUserQuarantineTag, TargetedDomainProtectionAction, TargetedDomainQuarantineTag, EnableOrganizationDomainsProtection
57+
Where-Object -Property Name -In $PolicyName |
58+
Select-Object Name, Enabled, PhishThresholdLevel, EnableMailboxIntelligence, EnableMailboxIntelligenceProtection, EnableSpoofIntelligence, EnableFirstContactSafetyTips, EnableSimilarUsersSafetyTips, EnableSimilarDomainsSafetyTips, EnableUnusualCharactersSafetyTips, EnableUnauthenticatedSender, EnableViaTag, AuthenticationFailAction, SpoofQuarantineTag, MailboxIntelligenceProtectionAction, MailboxIntelligenceQuarantineTag, TargetedUserProtectionAction, TargetedUserQuarantineTag, TargetedDomainProtectionAction, TargetedDomainQuarantineTag, EnableOrganizationDomainsProtection
5959

6060
$StateIsCorrect = ($CurrentState.Name -eq $PolicyName) -and
6161
($CurrentState.Enabled -eq $true) -and
@@ -82,8 +82,8 @@ function Invoke-CIPPStandardAntiPhishPolicy {
8282
$AcceptedDomains = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AcceptedDomain'
8383

8484
$RuleState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AntiPhishRule' |
85-
Where-Object -Property Name -EQ "CIPP $PolicyName" |
86-
Select-Object Name, AntiPhishPolicy, Priority, RecipientDomainIs
85+
Where-Object -Property Name -EQ "CIPP $PolicyName" |
86+
Select-Object Name, AntiPhishPolicy, Priority, RecipientDomainIs
8787

8888
$RuleStateIsCorrect = ($RuleState.Name -eq "CIPP $PolicyName") -and
8989
($RuleState.AntiPhishPolicy -eq $PolicyName) -and

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,32 @@ function Invoke-CIPPStandardDisableUserSiteCreate {
3333

3434
If ($Settings.remediate -eq $true) {
3535

36-
if ($CurrentInfo.isSiteCreationEnabled) {
36+
if ($CurrentInfo.isSiteCreationEnabled -or $CurrentInfo.isSiteCreationUIEnabled) {
3737
try {
38-
$body = '{"isSiteCreationEnabled": false}'
38+
$body = '{"isSiteCreationEnabled": false, "isSiteCreationUIEnabled": false}'
3939
$null = New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/admin/sharepoint/settings' -AsApp $true -Type patch -Body $body -ContentType 'application/json'
40-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Disabled standard users from creating sites' -sev Info
40+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Disabled standard users from creating sites and adjusted UI setting' -sev Info
4141
} catch {
4242
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
4343
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable standard users from creating sites: $ErrorMessage" -sev Error
4444
}
4545
} else {
46-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are already disabled from creating sites' -sev Info
46+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are already disabled from creating sites and UI setting is adjusted' -sev Info
4747
}
4848

4949
}
5050

5151
if ($Settings.alert -eq $true) {
5252

53-
if ($CurrentInfo.isSiteCreationEnabled -eq $false) {
54-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are not allowed to create sites' -sev Info
53+
if ($CurrentInfo.isSiteCreationEnabled -eq $false -and $CurrentInfo.isSiteCreationUIEnabled -eq $false) {
54+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are not allowed to create sites and UI setting is disabled' -sev Info
5555
} else {
56-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are allowed to create sites' -sev Alert
56+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Standard users are allowed to create sites or UI setting is enabled' -sev Alert
5757
}
5858
}
5959

6060
if ($Settings.report -eq $true) {
6161
Add-CIPPBPAField -FieldName 'DisableUserSiteCreate' -FieldValue $CurrentInfo.isSiteCreationEnabled -StoreAs bool -Tenant $tenant
62+
Add-CIPPBPAField -FieldName 'DisableUserSiteCreateUI' -FieldValue $CurrentInfo.isSiteCreationUIEnabled -StoreAs bool -Tenant $tenant
6263
}
6364
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Function Invoke-CIPPStandardTeamsGlobalMeetingPolicy {
3838
$StateIsCorrect = ($CurrentState.AllowAnonymousUsersToJoinMeeting -eq $false) -and
3939
($CurrentState.AllowAnonymousUsersToStartMeeting -eq $false) -and
4040
($CurrentState.AutoAdmittedUsers -eq 'EveryoneInCompanyExcludingGuests') -and
41-
($CurrentState.AllowPSTNUsersToBypassLobby -eq $false)
42-
($CurrentState.MeetingChatEnabledType -eq 'EnabledExceptAnonymous')
43-
($CurrentState.DesignatedPresenterRoleMode -eq $Settings.DesignatedPresenterRoleMode)
41+
($CurrentState.AllowPSTNUsersToBypassLobby -eq $false) -and
42+
($CurrentState.MeetingChatEnabledType -eq 'EnabledExceptAnonymous') -and
43+
($CurrentState.DesignatedPresenterRoleMode -eq $Settings.DesignatedPresenterRoleMode) -and
4444
($CurrentState.AllowExternalParticipantGiveRequestControl -eq $false)
4545

4646
if ($Settings.remediate -eq $true) {

Package.zip

-32.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)