Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Misc

21 Aug 2024
💬 EN

Table of Contents

TODO: Break all this up

What are all the Entra commands, again?

Get-Command -Module 'Microsoft.Graph.Entra' -Name 'Get-*'

Research someone’s Entra group memberships

Get-EntraUserMembership `
    -ObjectId (Read-Host -Prompt 'Entra User ID or principal') `
| Select-Object `
    -Property @( `
        'displayName' `
        , 'description' `
        , 'mailNickname' `
        , 'mailEnabled' `
        , 'securityEnabled' `
        , 'groupTypes' `
        , 'Id'
    ) `
| Sort-Object `
    -Property 'displayName' `
| Format-List

Azure Communication Service email-sending stuff

Set up a custom role definition:

az role definition create `
    --subscription (Read-Host -Prompt 'Enter your Azure subscription here') `
    --role-definition (`
        ( `
            @{
                Name = 'Communication Service Mail Sender'
                Description = 'Minimal set of permissions required to send mail with Azure Communication Service.'
                AssignableScopes = @(
                    (Read-Host -Prompt 'Enter an assignable scope here')
                )
                Permissions = @(
                    @{
                        Actions = @(
                            'Microsoft.Communication/CommunicationServices/Write',
                            'Microsoft.Communication/CommunicationServices/Read',
                            'Microsoft.Communication/EmailServices/read'
                        )
                        NotActions = @()
                        DataActions = @()
                        NotDataActions = @()
                    }
                )
            } `
            | ConvertTo-Json -Depth 5 -Compress
        ).replace('"', '\"') `
    )

Then give myself that power.

az role assignment create `
    --subscription (Read-Host -Prompt 'Enter your Azure subscription here') `
    --assignee-object-id ( `
        az ad signed-in-user show `
            --query 'id' `
            --output 'tsv' `
    ) `
    --assignee-principal-type 'User' `
    --description 'Give myself permissions to send mail with Azure Communication Service.' `
    --scope (Read-Host -Prompt 'Enter your full ACS ID here') `
    --role 'Communication Service Mail Sender'

Then send myself an email (replace YOURSUBDOMAIN, ‘[email protected], and BIG-HEX-GUID-HERE`).

using Azure.Identity;
using Azure.Communication.Email;

var magicAzureCredential = new DefaultAzureCredential();
EmailClient emailClient = new(endpoint: new Uri("https://YOURSUBDOMAIN.communication.azure.com/"), credential: magicAzureCredential);

EmailContent emailContent = new(subject: "TestACS")
{
    PlainText = "Howdy hi"
};

EmailRecipients emailRecipients = new(
    to: new List<EmailAddress>()
    {
        new EmailAddress("[email protected]")
    });

EmailMessage emailMessage = new(senderAddress: "[email protected]", recipients: emailRecipients, content: emailContent);
EmailSendOperation emailSendOperation = emailClient.Send(Azure.WaitUntil.Completed, message: emailMessage);
Console.WriteLine(emailSendOperation.Value.Status);
--- ---