forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/BNWEIN/CIPP-API into dev
- Loading branch information
Showing
2 changed files
with
20 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ if ($AddMembers) { | |
$AddMembers | ForEach-Object { | ||
try { | ||
$member = $_ | ||
$MemberIDs = "https://graph.microsoft.com/v1.0/directoryObjects/$($member)" | ||
$MemberName = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($_)" -tenantid $Userobj.tenantid).mail | ||
if ($member -like '*#EXT#*') { $member = [System.Web.HttpUtility]::UrlEncode($member) } | ||
$MemberIDs = "https://graph.microsoft.com/v1.0/directoryObjects/" + (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($member)" -tenantid $Userobj.tenantid).id | ||
$addmemberbody = "{ `"[email protected]`": $(ConvertTo-Json @($MemberIDs)) }" | ||
if ($userobj.groupType -eq "Distribution list" -or $userobj.groupType -eq "Mail-Enabled Security") { | ||
$Params = @{ Identity = $userobj.groupid; Member = $member; BypassSecurityGroupManagerCheck = $true } | ||
|
@@ -29,10 +29,10 @@ if ($AddMembers) { | |
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups/$($userobj.groupid)" -tenantid $Userobj.tenantid -type patch -body $addmemberbody -Verbose | ||
} | ||
Write-LogMessage -API $APINAME -tenant $Userobj.tenantid -user $request.headers.'x-ms-client-principal' -message "Added $member to $($userobj.groupid) group" -Sev "Info" | ||
$body = $results.add("Success. $MemberName has been added") | ||
$body = $results.add("Success. $member has been added") | ||
} | ||
catch { | ||
$body = $results.add("Failed to add member $memberName to $($userobj.Groupid): $($_.Exception.Message)") | ||
$body = $results.add("Failed to add member $member to $($userobj.Groupid): $($_.Exception.Message)") | ||
} | ||
} | ||
|
||
|
@@ -48,11 +48,12 @@ if ($AddContacts) { | |
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Add-DistributionGroupMember" -cmdParams $params -UseSystemMailbox $true | ||
Write-LogMessage -API $APINAME -tenant $Userobj.tenantid -user $request.headers.'x-ms-client-principal' -message "Added $member to $($userobj.groupid) group" -Sev "Info" | ||
$body = $results.add("Success. $member has been added") | ||
} else { | ||
Write-LogMessage -API $APINAME -tenant $Userobj.tenantid -user $request.headers.'x-ms-client-principal' -message "You cannot add a contact to a security group" -Sev "Error" | ||
$body = $results.add("You cannot add a contact to a security group") | ||
} | ||
else { | ||
Write-LogMessage -API $APINAME -tenant $Userobj.tenantid -user $request.headers.'x-ms-client-principal' -message "You cannot add a contact to a security group" -Sev "Error" | ||
$body = $results.add("You cannot add a contact to a security group") | ||
} | ||
} | ||
} | ||
catch { | ||
$body = $results.add("Failed to add member $member to $($userobj.Groupid): $($_.Exception.Message)") | ||
} | ||
|
@@ -64,17 +65,17 @@ $RemoveMembers = ($userobj.Removemember).value | |
try { | ||
if ($RemoveMembers) { | ||
$RemoveMembers | ForEach-Object { | ||
$MemberInfo = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($_)" -tenantid $Userobj.tenantid) | ||
$member = $_ | ||
if ($userobj.groupType -eq "Distribution list" -or $userobj.groupType -eq "Mail-Enabled Security") { | ||
$Params = @{ Identity = $userobj.groupid; Member = $member ; BypassSecurityGroupManagerCheck = $true } | ||
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Remove-DistributionGroupMember" -cmdParams $params -UseSystemMailbox $true | ||
} | ||
else { | ||
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups/$($userobj.groupid)/members/$($Member)/`$ref" -tenantid $Userobj.tenantid -type DELETE | ||
$MemberInfo = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($_)" -tenantid $Userobj.tenantid) | ||
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups/$($userobj.groupid)/members/$($MemberInfo.id)/`$ref" -tenantid $Userobj.tenantid -type DELETE | ||
} | ||
Write-LogMessage -API $APINAME -tenant $Userobj.tenantid -user $request.headers.'x-ms-client-principal' -message "Removed $member from $($userobj.groupid) group" -Sev "Info" | ||
$body = $results.add("Success. Member $($memberinfo.mail) has been removed") | ||
$body = $results.add("Success. Member $member has been removed") | ||
} | ||
} | ||
} | ||
|
@@ -150,16 +151,16 @@ if ($userobj.allowExternal -eq 'true') { | |
|
||
if ($userobj.sendCopies -eq 'true') { | ||
try { | ||
$Params = @{ Identity = $userobj.Groupid; subscriptionEnabled = $true; AutoSubscribeNewMembers = $true } | ||
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Set-UnifiedGroup" -cmdParams $params -useSystemMailbox $true | ||
$Params = @{ Identity = $userobj.Groupid; subscriptionEnabled = $true; AutoSubscribeNewMembers = $true } | ||
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Set-UnifiedGroup" -cmdParams $params -useSystemMailbox $true | ||
|
||
$MemberParams = @{ Identity = $userobj.Groupid; LinkType = "members" } | ||
$Members = New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Get-UnifiedGrouplinks" -cmdParams $MemberParams | ||
$MemberParams = @{ Identity = $userobj.Groupid; LinkType = "members" } | ||
$Members = New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Get-UnifiedGrouplinks" -cmdParams $MemberParams | ||
|
||
$MemberSmtpAddresses = $Members | ForEach-Object { $_.PrimarySmtpAddress } | ||
$MemberSmtpAddresses = $Members | ForEach-Object { $_.PrimarySmtpAddress } | ||
|
||
$subscriberParams = @{ Identity = $userobj.Groupid; LinkType = "subscribers"; Links = @($MemberSmtpAddresses) } | ||
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Add-UnifiedGrouplinks" -cmdParams $subscriberParams -Anchor $userobj.mail | ||
$subscriberParams = @{ Identity = $userobj.Groupid; LinkType = "subscribers"; Links = @($MemberSmtpAddresses) } | ||
New-ExoRequest -tenantid $Userobj.tenantid -cmdlet "Add-UnifiedGrouplinks" -cmdParams $subscriberParams -Anchor $userobj.mail | ||
|
||
|
||
$body = $results.add("Send Copies of team emails and events to team members inboxes for $($userobj.mail) enabled.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters