$msGraphAppId = "00000003-0000-0000-c000-000000000000" $scopeMailSend = "Mail.Send" $spOnlineWebClientExtensibilityAppId = "08e18876-6177-487e-b8b5-cf950c1e598c" # SharePoint Online Web Client Extensibility $resourceGrant = $null # Prompt to install the required modules if not yet installed if ($null -eq (Get-Module -ListAvailable -Name Microsoft.Graph.Applications) -or $null -eq (Get-Module -ListAvailable -Name Microsoft.Graph.Identity.SignIns)) { $response = Read-Host -Prompt "Running this script requires Microsoft.Graph modules that are not yet installed. Install now? (Y/N)" if ($response -eq "Y") { if ($null -eq (Get-Module -ListAvailable -Name Microsoft.Graph.Applications)) { Install-Module -Name Microsoft.Graph.Applications -Scope CurrentUser -Force -AllowClobber } if ($null -eq (Get-Module -ListAvailable -Name Microsoft.Graph.Identity.SignIns)) { Install-Module -Name Microsoft.Graph.Identity.SignIns -Scope CurrentUser -Force -AllowClobber } } else { Write-Host "The script cannot continue without the Microsoft.Graph modules. Exiting." -ForegroundColor Red exit } } Connect-MgGraph -Scopes "Application.ReadWrite.All", "Directory.ReadWrite.All" -NoWelcome try { # Get the SPFx Service Principal $spfx = Get-MgServicePrincipal -Filter "appid eq '$spOnlineWebClientExtensibilityAppId'" -ErrorAction Stop # Get the endpoint service princpal (required to identify the object ID) $resource = Get-MgServicePrincipal -Filter "appid eq '$msGraphAppId'" -ErrorAction Stop # Get the scopes granted for the endpoint $spfxGrants = Get-MgServicePrincipalOauth2PermissionGrant -ServicePrincipalId $spfx.Id -ErrorAction Stop foreach ($spfxGrant in $spfxGrants) { if ($spfxGrant.ResourceId -eq $resource.Id) { $resourceGrant = $spfxGrant break } } # If some scopes have already been granted for the endpoint, we check if the scope we are about to add already exists there if ($null -ne $resourceGrant) { if ($resourceGrant.Scope | Select-String $scopeMailSend -Quiet ) { Write-Host "$($resource.DisplayName) $scopeMailSend has already been granted for SharePoint Online Web Client Extensibility" -ForegroundColor Green continue } # The scope does not yet exist; add it to the property and update it $resourceGrant.Scope += " $scopeMailSend" Update-MgOauth2PermissionGrant -OAuth2PermissionGrantId $resourceGrant.Id -Scope $resourceGrant.Scope -ErrorAction Stop | Out-Null } # Otherwise, create a new object with the scope else { $params = @{ "clientId" = $spfx.id "consentType" = "AllPrincipals" "resourceId" = $resource.id "scope" = $scopeMailSend } New-MgOauth2PermissionGrant -BodyParameter $params -ErrorAction Stop | Out-Null } Write-Host "$($resource.DisplayName) $scopeMailSend granted for SharePoint Online Web Client Extensibility." -ForegroundColor Green } catch { Write-Host "The following error occurred: $_.Exception" -ForegroundColor Red } finally{ $_ = Disconnect-MgGraph # Assigning the output to a variable hides it from the terminal }
Eigenschaft |
Erforderlich |
Art |
Beschreibung |
Von |
Nein |
String |
Eine E-Mail-Adresse oder ein Ausdruck, der als E-Mail-Adresse ausgewertet werden soll, die als Absender verwendet werden soll. Wenn das Feld leer gelassen wird, wird der aktuelle Benutzer als Absendername verwendet. Wenn die Option "Von" angegeben ist, müssen alle SharePoint-Benutzer über mindestens eine der Berechtigungen "Senden im Auftrag von" oder "Senden als" verfügen, die dem Absenderpostfach erteilt wurden. Außerdem sollte die E-Mail-Adresse des Absenders ein Microsoft-Organisationskonto sein. |
An |
ja |
String |
Empfänger der E-Mail: Benutzer oder Ausdruck, der als E-Mail-Adresse ausgewertet werden soll. Um es an mehrere Benutzer zu senden, verwenden Sie ein ";" (Semikolon), um die E-Mail-Adressen zu trennen. |
CC |
Nein |
String |
Benutzer oder Ausdruck, der als E-Mail-Adresse ausgewertet werden soll, die eine Kopie der Nachricht erhält. Um es an mehrere Benutzer zu senden, verwenden Sie ein ";" (Semikolon), um die E-Mail-Adressen zu trennen. |
BCC |
Nein |
String |
Benutzer oder Ausdruck, der als E-Mail-Adresse ausgewertet werden soll, die eine Kopie der Nachricht erhält und vor den anderen Empfängern verborgen bleibt. Um es an mehrere Benutzer zu senden, verwenden Sie ein ";" (Semikolon), um die E-Mail-Adressen zu trennen. |
Betreff |
ja |
String |
Betreff der zu sendenden E-Mail. |
Körper |
Nein |
String |
Zu sendende Nachricht. Sie können HTML-Tags verwenden, um den Text der E-Mail zu formatieren. |
Als Text senden |
Nein |
Boolesch |
Wenn diese Option aktiviert ist, werden E-Mails im Klartext gesendet, andernfalls werden sie als HTML-Mail gesendet. |