Skip to content

Commit

Permalink
Merge pull request #1247 from kris6673/devices
Browse files Browse the repository at this point in the history
New standard StaleEntraDevices and more
  • Loading branch information
KelvinTegelaar authored Jan 19, 2025
2 parents 8216b06 + 48867b9 commit 8587a05
Show file tree
Hide file tree
Showing 114 changed files with 559 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@ Function Invoke-ExecDeviceDelete {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Interact with query parameters or the body of the request.
$ExecutingUser = $Request.headers.'x-ms-client-principal'
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Interact with body parameters or the body of the request.
$TenantFilter = $Request.body.tenantFilter ?? $Request.Query.tenantFilter
$Action = $Request.body.action ?? $Request.Query.action
$DeviceID = $Request.body.ID ?? $Request.Query.ID

try {
$url = "https://graph.microsoft.com/beta/devices/$($request.query.id)"
if ($Request.query.action -eq 'delete') {
$ActionResult = New-GraphPOSTRequest -uri $url -type DELETE -tenantid $Request.Query.TenantFilter
} elseif ($Request.query.action -eq 'disable') {
$ActionResult = New-GraphPOSTRequest -uri $url -type PATCH -tenantid $Request.Query.TenantFilter -body '{"accountEnabled": false }'
} elseif ($Request.query.action -eq 'enable') {
$ActionResult = New-GraphPOSTRequest -uri $url -type PATCH -tenantid $Request.Query.TenantFilter -body '{"accountEnabled": true }'
}
Write-Host $ActionResult
$body = [pscustomobject]@{'Results' = "Executed action $($Request.query.action) on $($Request.query.id)" }
$Results = Set-CIPPDeviceState -Action $Action -DeviceID $DeviceID -TenantFilter $TenantFilter -ExecutingUser $ExecutingUser -APIName $APINAME
$StatusCode = [HttpStatusCode]::OK
} catch {
$body = [pscustomobject]@{'Results' = "Failed to queue action $($Request.query.action) on $($request.query.id): $($_.Exception.Message)" }
$Results = $_.Exception.Message
$StatusCode = [HttpStatusCode]::BadRequest
}

Write-Host $Results
$body = [pscustomobject]@{'Results' = "$Results" }

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
StatusCode = $StatusCode
Body = $body
})

Expand Down
79 changes: 79 additions & 0 deletions Modules/CIPPCore/Public/Set-CIPPDeviceState.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function Set-CIPPDeviceState {
<#
.SYNOPSIS
Sets or modifies the state of a device in Microsoft Graph.
.DESCRIPTION
This function allows you to enable, disable, or delete a device by making
corresponding requests to the Microsoft Graph API. It logs the result
and returns a success or error message based on the outcome.
.PARAMETER Action
Specifies the action to perform on the device. Valid actions are:
- Enable: Enable the device
- Disable: Disable the device
- Delete: Remove the device from the tenant
.PARAMETER DeviceID
Specifies the unique identifier (Object ID) of the device to be managed.
.PARAMETER TenantFilter
Specifies the tenant ID or domain against which to perform the operation.
.PARAMETER ExecutingUser
Specifies the user who initiated the request for logging purposes.
.PARAMETER APIName
Specifies the name of the API call for logging purposes. Defaults to 'Set Device State'.
.EXAMPLE
Set-CIPPDeviceState -Action Enable -DeviceID "1234abcd-5678-efgh-ijkl-9012mnopqrst" -TenantFilter "contoso.onmicrosoft.com" -ExecutingUser "[email protected]"
This command enables the specified device within the given tenant.
.EXAMPLE
Set-CIPPDeviceState -Action Delete -DeviceID "1234abcd-5678-efgh-ijkl-9012mnopqrst" -TenantFilter "contoso.onmicrosoft.com"
This command removes the specified device from the tenant.
#>
param (
[Parameter(Mandatory = $true)][ValidateSet('Enable', 'Disable', 'Delete')]$Action,

[ValidateScript({
if ([Guid]::TryParse($_, [ref] [Guid]::Empty)) {
$true
} else {
throw 'DeviceID must be a valid GUID.'
}
})]
[Parameter(Mandatory = $true)]$DeviceID,

[Parameter(Mandatory = $true)]$TenantFilter,
$ExecutingUser,
$APIName = 'Set Device State'
)
$Url = "https://graph.microsoft.com/beta/devices/$($DeviceID)"

try {
switch ($Action) {
'Delete' {
$ActionResult = New-GraphPOSTRequest -uri $Url -type DELETE -tenantid $TenantFilter
}
'Disable' {
$ActionResult = New-GraphPOSTRequest -uri $Url -type PATCH -tenantid $TenantFilter -body '{"accountEnabled": false }'
}
'Enable' {
$ActionResult = New-GraphPOSTRequest -uri $Url -type PATCH -tenantid $TenantFilter -body '{"accountEnabled": true }'
}
}
Write-Host $ActionResult
Write-LogMessage -user $ExecutingUser -API $APIName -message "Executed action $($Action) on $($DeviceID)" -Sev Info
return "Executed action $($Action) on $($DeviceID)"
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $ExecutingUser -API $APIName -message "Failed to queue action $($Action) on $($DeviceID). Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
throw "Failed to queue action $($Action) on $($DeviceID). Error: $($ErrorMessage.NormalizedError)"
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Invoke-CIPPStandardActivityBasedTimeout {
"CIS"
"spo_idle_session_timeout"
ADDEDCOMPONENT
{"type":"Select","label":"Select value","name":"standards.ActivityBasedTimeout.timeout","values":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
{"type":"select","multiple":false,"label":"Select value","name":"standards.ActivityBasedTimeout.timeout","options":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
IMPACT
Medium Impact
POWERSHELLEQUIVALENT
Expand All @@ -27,7 +27,7 @@ function Invoke-CIPPStandardActivityBasedTimeout {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#medium-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Invoke-CIPPStandardAddDKIM {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Invoke-CIPPStandardAnonReportDisable {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ function Invoke-CIPPStandardAntiPhishPolicy {
"mdo_phishthresholdlevel"
ADDEDCOMPONENT
{"type":"number","label":"Phishing email threshold. (Default 1)","name":"standards.AntiPhishPolicy.PhishThresholdLevel","default":1}
{"type":"boolean","label":"Show first contact safety tip","name":"standards.AntiPhishPolicy.EnableFirstContactSafetyTips","default":true}
{"type":"boolean","label":"Show user impersonation safety tip","name":"standards.AntiPhishPolicy.EnableSimilarUsersSafetyTips","default":true}
{"type":"boolean","label":"Show domain impersonation safety tip","name":"standards.AntiPhishPolicy.EnableSimilarDomainsSafetyTips","default":true}
{"type":"boolean","label":"Show user impersonation unusual characters safety tip","name":"standards.AntiPhishPolicy.EnableUnusualCharactersSafetyTips","default":true}
{"type":"Select","label":"If the message is detected as spoof by spoof intelligence","name":"standards.AntiPhishPolicy.AuthenticationFailAction","values":[{"label":"Quarantine the message","value":"Quarantine"},{"label":"Move to Junk Folder","value":"MoveToJmf"}]}
{"type":"Select","label":"Quarantine policy for Spoof","name":"standards.AntiPhishPolicy.SpoofQuarantineTag","values":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
{"type":"Select","label":"If a message is detected as user impersonation","name":"standards.AntiPhishPolicy.TargetedUserProtectionAction","values":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"Select","label":"Quarantine policy for user impersonation","name":"standards.AntiPhishPolicy.TargetedUserQuarantineTag","values":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
{"type":"Select","label":"If a message is detected as domain impersonation","name":"standards.AntiPhishPolicy.TargetedDomainProtectionAction","values":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"Select","label":"Quarantine policy for domain impersonation","name":"standards.AntiPhishPolicy.TargetedDomainQuarantineTag","values":[{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"},{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"}]}
{"type":"Select","label":"If Mailbox Intelligence detects an impersonated user","name":"standards.AntiPhishPolicy.MailboxIntelligenceProtectionAction","values":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"Select","label":"Apply quarantine policy","name":"standards.AntiPhishPolicy.MailboxIntelligenceQuarantineTag","values":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
{"type":"switch","label":"Show first contact safety tip","name":"standards.AntiPhishPolicy.EnableFirstContactSafetyTips","default":true}
{"type":"switch","label":"Show user impersonation safety tip","name":"standards.AntiPhishPolicy.EnableSimilarUsersSafetyTips","default":true}
{"type":"switch","label":"Show domain impersonation safety tip","name":"standards.AntiPhishPolicy.EnableSimilarDomainsSafetyTips","default":true}
{"type":"switch","label":"Show user impersonation unusual characters safety tip","name":"standards.AntiPhishPolicy.EnableUnusualCharactersSafetyTips","default":true}
{"type":"select","multiple":false,"label":"If the message is detected as spoof by spoof intelligence","name":"standards.AntiPhishPolicy.AuthenticationFailAction","options":[{"label":"Quarantine the message","value":"Quarantine"},{"label":"Move to Junk Folder","value":"MoveToJmf"}]}
{"type":"select","multiple":false,"label":"Quarantine policy for Spoof","name":"standards.AntiPhishPolicy.SpoofQuarantineTag","options":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
{"type":"select","multiple":false,"label":"If a message is detected as user impersonation","name":"standards.AntiPhishPolicy.TargetedUserProtectionAction","options":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"select","multiple":false,"label":"Quarantine policy for user impersonation","name":"standards.AntiPhishPolicy.TargetedUserQuarantineTag","options":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
{"type":"select","multiple":false,"label":"If a message is detected as domain impersonation","name":"standards.AntiPhishPolicy.TargetedDomainProtectionAction","options":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"select","multiple":false,"label":"Quarantine policy for domain impersonation","name":"standards.AntiPhishPolicy.TargetedDomainQuarantineTag","options":[{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"},{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"}]}
{"type":"select","multiple":false,"label":"If Mailbox Intelligence detects an impersonated user","name":"standards.AntiPhishPolicy.MailboxIntelligenceProtectionAction","options":[{"label":"Move to Junk Folder","value":"MoveToJmf"},{"label":"Delete the message before its delivered","value":"Delete"},{"label":"Quarantine the message","value":"Quarantine"}]}
{"type":"select","multiple":false,"label":"Apply quarantine policy","name":"standards.AntiPhishPolicy.MailboxIntelligenceQuarantineTag","options":[{"label":"AdminOnlyAccessPolicy","value":"AdminOnlyAccessPolicy"},{"label":"DefaultFullAccessPolicy","value":"DefaultFullAccessPolicy"},{"label":"DefaultFullAccessWithNotificationPolicy","value":"DefaultFullAccessWithNotificationPolicy"}]}
IMPACT
Low Impact
POWERSHELLEQUIVALENT
Expand All @@ -45,7 +45,7 @@ function Invoke-CIPPStandardAntiPhishPolicy {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/defender-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Invoke-CIPPStandardAppDeploy {
TAG
"lowimpact"
ADDEDCOMPONENT
{"type":"input","name":"standards.AppDeploy.appids","label":"Application IDs, comma separated"}
{"type":"textField","name":"standards.AppDeploy.appids","label":"Application IDs, comma separated"}
IMPACT
Low Impact
POWERSHELLEQUIVALENT
Expand All @@ -24,7 +24,7 @@ function Invoke-CIPPStandardAppDeploy {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/entra-aad-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ function Invoke-CIPPStandardAtpPolicyForO365 {
.SYNOPSIS
(Label) Default Atp Policy For O365
.DESCRIPTION
(Helptext) This creates a Atp policy that enables Defender for Office 365 for Sharepoint, OneDrive and Microsoft Teams.
(DocsDescription) This creates a Atp policy that enables Defender for Office 365 for Sharepoint, OneDrive and Microsoft Teams.
(Helptext) This creates a Atp policy that enables Defender for Office 365 for SharePoint, OneDrive and Microsoft Teams.
(DocsDescription) This creates a Atp policy that enables Defender for Office 365 for SharePoint, OneDrive and Microsoft Teams.
.NOTES
CAT
Defender Standards
TAG
"lowimpact"
"CIS"
ADDEDCOMPONENT
{"type":"boolean","label":"Allow people to click through Protected View even if Safe Documents identified the file as malicious","name":"standards.AtpPolicyForO365.AllowSafeDocsOpen","default":false}
{"type":"switch","label":"Allow people to click through Protected View even if Safe Documents identified the file as malicious","name":"standards.AtpPolicyForO365.AllowSafeDocsOpen","default":false,"required":false}
IMPACT
Low Impact
POWERSHELLEQUIVALENT
Expand All @@ -26,7 +26,7 @@ function Invoke-CIPPStandardAtpPolicyForO365 {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/defender-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Invoke-CIPPStandardAuditLog {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Invoke-CIPPStandardAutoExpandArchive {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Invoke-CIPPStandardBookings {
TAG
"mediumimpact"
ADDEDCOMPONENT
{"type":"Select","label":"Select value","name":"standards.Bookings.state","values":[{"label":"Enabled","value":"true"},{"label":"Disabled","value":"false"}]}
{"type":"select","multiple":false,"label":"Select value","name":"standards.Bookings.state","options":[{"label":"Enabled","value":"true"},{"label":"Disabled","value":"false"}]}
IMPACT
Medium Impact
POWERSHELLEQUIVALENT
Expand All @@ -24,7 +24,7 @@ function Invoke-CIPPStandardBookings {
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#medium-impact
#>

param($Tenant, $Settings)
Expand Down
Loading

0 comments on commit 8587a05

Please sign in to comment.