Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push ListCalendarPerms #86

Merged
merged 15 commits into from
Dec 3, 2021
2 changes: 1 addition & 1 deletion Durable_AlertsQueue/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ param($name)

$Tenants = Get-Tenants

$Tenants
$Tenants
19 changes: 19 additions & 0 deletions ListCalendarPermissions/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
38 changes: 38 additions & 0 deletions ListCalendarPermissions/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
$UserID = $request.Query.UserID
$Tenantfilter = $request.Query.tenantfilter
Write-Information "My username is $UserID"
Write-Information "My tenantfilter is $Tenantfilter"
if ($UserID -eq $null) { exit }
#$userid = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($username)" -tenantid $Tenantfilter).id
$UserDetails = New-GraphGetRequest -uri "https://outlook.office365.com/adminapi/beta/$($tenantfilter)/Mailbox('$UserID')" -Tenantid $tenantfilter -scope ExchangeOnline -noPagination $true
$Results = [System.Collections.ArrayList]@()
$upn = "[email protected]"
$tokenvalue = ConvertTo-SecureString (Get-GraphToken -AppID 'a0c73c16-a7e3-4564-9a95-2bdf47383716' -RefreshToken $ENV:ExchangeRefreshToken -Scope 'https://outlook.office365.com/.default' -Tenantid $tenantFilter).Authorization -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($upn, $tokenValue)
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell-liveid?DelegatedOrg=$($tenantFilter)&BasicAuthToOAuthConversion=true" -Credential $credential -Authentication Basic -AllowRedirection -ea Stop
$upn = '[email protected]'


try {
Import-PSSession $session -ea Silentlycontinue -AllowClobber -CommandName "Get-MailboxFolderPermission"
# $CalPerms = (Get-MailboxFolderPermission -Identity $($userid.PrimarySmtpAddress))
$CalPerms = (Get-MailboxFolderPermission -Identity $($UserDetails.PrimarySmtpAddress))

Get-PSSession | Remove-PSSession
Log-request -API 'List Calendar Permissions' -tenant $tenantfilter -message "Calendar permissions listed for $($tenantfilter)" -sev Info
} catch {
Log-request -API 'List Calendar Permissions' -tenant $tenantfilter -message "Failed to list calendar permissions. Error: $($_.exception.message)" -sev Error
}

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