Skip to content

Commit

Permalink
Merge pull request #470 from BNWEIN/dev
Browse files Browse the repository at this point in the history
Updated GraphHelper.psm1
  • Loading branch information
KelvinTegelaar authored Nov 13, 2023
2 parents c6ad777 + a5933df commit dd47c78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion GraphHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function Remove-CIPPCache {
function New-ExoRequest ($tenantid, $cmdlet, $cmdParams, $useSystemMailbox, $Anchor, $NoAuthCheck) {
if ((Get-AuthorisedRequest -TenantID $tenantid) -or $NoAuthCheck -eq $True) {
$token = Get-ClassicAPIToken -resource 'https://outlook.office365.com' -Tenantid $tenantid
$tenant = (get-tenants -IncludeErrors | Where-Object -Property defaultDomainName -EQ $tenantid).customerId
$tenant = (get-tenants -IncludeErrors | Where-Object { $_.defaultDomainName -eq $tenantid -or $_.customerId -eq $tenantid }).customerId
if ($cmdParams) {
$Params = $cmdParams
}
Expand Down
10 changes: 7 additions & 3 deletions Modules/CIPPCore/Public/Remove-CIPPGroups.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
function Remove-CIPPGroups {
[CmdletBinding()]
param(
$userid,
$Username,
$tenantFilter,
$APIName = "Remove From Groups",
$ExecutingUser,
$Username
$userid
)

$AllGroups = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/?$select=DisplayName,mailEnabled" -tenantid $tenantFilter)
if (-not $userid) {
$userid = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($Username)" -tenantid $Tenantfilter).id
}
$AllGroups = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/?`$select=displayName,mailEnabled,id,groupTypes" -tenantid $tenantFilter)

(New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userid)/GetMemberGroups" -tenantid $tenantFilter -type POST -body '{"securityEnabledOnly": false}').value | ForEach-Object -Parallel {
Import-Module CIPPCore
Import-Module '.\GraphHelper.psm1'
$group = $_

Expand Down
5 changes: 3 additions & 2 deletions Modules/CIPPCore/Public/Remove-CIPPMobileDevice.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ function Remove-CIPPMobileDevice {
$devices = New-ExoRequest -tenantid $tenantFilter -cmdlet "Get-MobileDevice" -Anchor $username -cmdParams @{mailbox = $username } | ForEach-Object {
try {
New-ExoRequest -tenantid $tenantFilter -cmdlet "Remove-MobileDevice" -Anchor $username -cmdParams @{Identity = $_.Identity }
"Removed device: $($_.FriendlyName)"
return "Removed device: $($_.FriendlyName)"
}
catch {
"Could not remove device: $($_.FriendlyName)"
return "Could not remove device: $($_.FriendlyName)"
continue
}
}

Write-LogMessage -user $ExecutingUser -API $APIName -message "Deleted mobile devices for $($username)" -Sev "Info" -tenant $tenantFilter
return "Deleted mobile devices for $($username)"
}
catch {
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not delete mobile devices for $($username): $($_.Exception.Message)" -Sev "Error" -tenant $tenantFilter
Expand Down

0 comments on commit dd47c78

Please sign in to comment.