Monthly Archives: January 2020

VIDEO – How to Add Contact for other users with MS Graph API

Wanted to share a quick demo for how to query and create Exchange Contacts for another user in Office 365 tenant with MS Graph API.   Biggest challenge was permission grant in two places (1) MS Graph API in Azure Applications and (2) Exchange Folder grant Owner to user executing the MS Graph API.  Updated blog post with second video to execute Graph API from PowerShell for automation and scheduling.   Cheers shades_smile

Video 1 – Graph Explorer Web GUI

Video 2 – Graph API from PowerShell

PowerShell – Grant Exchange Folder

$Session = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Add-MailboxFolderPermission -Identity "george@spjeff.com:\Contacts" –User "spjeff@spjeff.com" –AccessRights "Owner"

PowerShell – Execute Graph API

# from https://blog.mastykarz.nl/building-applications-office-365-apis-any-platform/
# Config
$clientID = "34f34d49-86b7-4437-a332-6fecaf95a244"
$tenantName = "spjeff.onmicrosoft.com"
$ClientSecret = "secret-goes-here"
$Username = "spjeff@spjeff.com"
$Password = "password-goes-here"
# Access Token
$ReqTokenBody = @{
    Grant_Type    = "Password"
    client_Id     = $clientID
    Client_Secret = $clientSecret
    Username      = $Username
    Password      = $Password
    Scope         = "https://graph.microsoft.com/.default"
} 
$TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$TokenResponse

# Data call - READ
$apis = @(
'https://graph.microsoft.com/v1.0/me/contacts',
'https://graph.microsoft.com/v1.0/me',
'https://graph.microsoft.com/v1.0/users',
'https://graph.microsoft.com/v1.0/users/george@spjeff.com/contacts')
$apis |% {
    Write-Host $_ -Fore Yellow
    Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $_ -Method GET -Body $body -ContentType "text/plain"
}
# Data call - WRITE
$newcontact = '{"givenName": "Test","surname": "Contact","emailAddresses": [{"address": "test@contact.com","name": "Pavel Bansky"}],"businessPhones": ["+1 732 555 0102"]}'
$api = 'https://graph.microsoft.com/v1.0/users/george@spjeff.com/contacts'
Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $api -Method "POST" -Body $newcontact -ContentType "application/json"

Screenshots

2020-01-28_06-59-19

2020-01-28_07-01-09

image

image

image

References

    Microsoft 365 Certified – Enterprise Administrator Expert

    Passed exams MS-100 and MS-101 to achieve new certification level.  Wanted to share study resources I found helpful.  Regular daily reading and hand written notes to paper increased memory.  Carry ink pen and highlighter everywhere.  Body and mind working together.  Check out “Why We Remember What We Write” to learn more.   “The movements involved when handwriting leave a motor memory in the sensorimotor part of the brain”

    Cheers.  shades_smile

    100519_0030_MS101StudyG1

    Resources

    Certification Route

    image

    VIDEO – Toggle Required Fields OFF

    When making bulk data changes to SharePoint List or Library you may need to temporarily turn off Required fields.   Opening this can allow us to import records, apply changes, and modify metadata without prompting that required fields are missing.   PowerShell below can help disable all Required fields OFF.    Script generates a CSV snapshot of prior configuration during run.    CSV can be used to restore original configuration for which fields are Required.

    Cheers shades_smile

    VIDEO

    PowerShell Code

    [CmdletBinding()]
    param (
        [bool]$required,
        [string]$restoreFilename
    )
    # Module
    Import-Module "SharePointPnPPowerShellOnline" -ErrorAction "SilentlyContinue" | Out-Null
    # Config
    $appid = "APP ID HERE"
    $appsecret = "APP SECRET HERE"
    function Main() {
        # Connect
        Connect-PnPOnline -Url "https://tenant.sharepoint.com/" -AppId $appid -AppSecret $appsecret 
        $ctx = Get-PnPContext
        $list = Get-PnPList "Test"
        $list
        if ($restoreFilename) {
            # ENABLE Required Fields
            $csv = Import-Csv $restoreFilename
            $fields = Get-PnPField -List $list
            foreach ($row in $csv) {
                $row.Guid
                $f = $fields | ? { $_.Id -eq $row.Guid }
                $f.Required = $true
                $f.Update()
            }
            $ctx.ExecuteQuery()
        }
        else {
            # DISABLE Required Fields
            $coll = @()
            $guid = (New-Guid).ToString()
            $fields = Get-PnPField -List $list
            foreach ($f in $fields) {
                if ($f.Required) {
                    Write-Host "CHANGED FIELD $($f.Title) NOT REQUIRED"
                    $f.Required = $false
                    $f.Update()
                    $coll += $f.Id
                }
            }
            $ctx.ExecuteQuery()
            $coll | Export-Csv "PNPToggleRequiredField-$guid.csv"
        }
    }
    # Main
    Main
    

    GitHub Link

    References

    VIDEO – PowerBI Monthly Updates

    Updates are released monthly for PowerBI desktop client.   Links below with helpful references to both Microsoft monthly release notes, download MSI, and monthly video notes.  

    Microsoft will eventually discontinue support for older PowerBI desktop versions (screenshot below).   To avoid outage and have latest features, update early and often.

    Cheers.  shades_smile

    Video

    Screenshot

    image

    References

    SharePoint Calendar Color Overlay (HEX DISPLAY)

    Quick reference below for the 7 Microsoft calendar overlay colors available in SharePoint Online as of 1/19/2020.   User Voice community has requested ability to add custom colors, but not yet implemented.  Upvote if you like at https://sharepoint.uservoice.com/forums/601165-suggestion-archive/suggestions/11317953-select-own-hex-colors-for-calendar-overlay.   Notes on how to create Calendar overlay at https://blog.virtosoftware.com/how-to-color-code-sharepoint-calendars/.

    Microsoft Color
    Dark Teal, #00485b
    Blue, #0078d4
    Dark Green, #288054
    Olive Green, #767956
    Red, #ed0033
    Dark Purple, #682a7a
    Dark Teal, #006984
    Dark Green, #134029
    Brown, #3b3c2a

    image

    Cheers shades_smile

    What’s in that patch? January 2020

    NOTE – PDF format updated to include both SharePoint 2013, 2016, and 2019 notes.

    Ever wondered what fixes are inside of a given CU?   Please see attached PDF with full detail. I wanted a new format for easy reading.   Show management and make the business case for why downtime should be taken to apply CUs.  Also posted at https://sharepointupdates.com/

    If you found this helpful, please leave a comment.    shades_smile_thumb_thumb_thumb_thumb[2]

    Download

    What’s in that patch – Jan 2020.PDF

    FIXED – MS Flow HTTP 400 – Managed Metadata

    Wanted to share resolution for tagging Managed Metadata term in MS Flow and seeing error HTTP 400.  Managed Metadata terms are stored in SharePoint with GUID identifiers.   That enables us to rename terms while preserving all current tag usage.  However, it means that we must use GUID when adding and updating tag values to ensure lookup saves successful.  Cheers shades_smile

    Error

    HTTP 400.  The data returned from the tagging UI was not formatted correctly.

    Resolution

    Format text for Managed Metadata tag as “VALUE | GUID”.  For example, here we have “JavaScript|6f634666-d2a6-4367-9b65-4bb4ab33afc6” in the MS Flow Set Variable set.  Publish, run flow, and confirm SPListItem successfully added to demo list.

    Video

    Screenshots

    image

    image

    image

    image

    image

    image

    VIDEO – Azure Function running F5 on localhost

    Wanted to share brief for creating a new Azure Function 2.0 on localhost.  Followed quick start wizard within Azure for steps.  Initially received error message pressing F5 but able to resolve by navigate down three folders and run command manually.  Root cause was local PowerShell configuration.   Updating “$profile” to remove Change Directory commands (“CD C:\CODE”) resolved the F5 error with Azure function not starting.

    Thank you to @nthonyChu and @fiveisprime for help troubleshooting.   Cheers.  shades_smile

    Error

    Unable to find project root. Expecting to find one of host.json, local.settings.json in project root.

    Resolution

    1. Launch PowerShell
    2. Run “notepad $profile
    3. Remove any “CD” commands with modify working directory
    4. Save and restart

    Workaround (Temporary)

    1. Navigate down 3 folders with cd “bin\debug\netcoreapp2.1\”
    2. Run “func start host

    Video

    Screenshots

    image

    image

    image

    image

    image

    Return to Top ▲Return to Top ▲