Skip to content

Commit

Permalink
Updated Sample - Graph Connector Ignite 2024 (#69)
Browse files Browse the repository at this point in the history
* Major update to ignite sample 2024

* remove old file

* Minor tweaks to dates

* MVP suffix
  • Loading branch information
pkbullock authored Nov 6, 2024
1 parent c54bdbb commit 13af305
Show file tree
Hide file tree
Showing 11 changed files with 12,335 additions and 8,155 deletions.
30 changes: 16 additions & 14 deletions samples/powershell-json-ignite/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function SetupGraphConnectorEntraId{
)

##TODO Check Config file or display name exists for the connector
Write-Host "Checking Graph Connector for Entra ID..."
Write-Host "Checking Graph Connector for Entra ID..." -ForegroundColor Blue

Connect-MgGraph -Scopes AppRoleAssignment.ReadWrite.All,Application.ReadWrite.All -NoWelcome

Expand All @@ -60,7 +60,7 @@ function SetupGraphConnectorEntraId{
$result = Get-MgApplication -Filter "DisplayName eq '$($DisplayName)'"

if(!$result){
Write-Host "Creating Graph Connector for Entra ID..." -NoNewline
Write-Host "Creating Graph Connector for Entra ID..." -NoNewline -ForegroundColor Blue
# create the application
$app = New-MgApplication -DisplayName $DisplayName -RequiredResourceAccess $requiredResourceAccess

Expand Down Expand Up @@ -95,7 +95,7 @@ function InitializeGraphConnection{
[string]$secretName
)

Write-Host "Initialise the Graph connection..."
Write-Host "Initialise the Graph connection..." -ForegroundColor Blue

$config = Get-Content -Path $cfgFileName | ConvertFrom-StringData
$credential = Get-Secret -Name $secretName
Expand All @@ -108,17 +108,14 @@ function InitializeGraphConnection{
#-----------------------------------------------------------

function Get-AdaptiveCard{
param(
[string]$path = ".\resultLayout.json"
)

Write-Host "Getting Adaptive Card from $path"

Write-Host "Getting Adaptive Card from $(Get-Location)\resultLayout.json"

# Initialize to an empty hashtable to explicitly define the type as hashtable.
# This is needed to avoid the breaking change introduced in PowerShell 7.3 - https://github.com/PowerShell/PowerShell/issues/18524.
# https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2352
[hashtable]$adaptiveCard = @{}
$adaptiveCard += Get-Content -Path ".\resultLayout.json" -Raw | ConvertFrom-Json -AsHashtable
$adaptiveCard += Get-Content -Path "$(Get-Location)\resultLayout.json" -Raw | ConvertFrom-Json -AsHashtable

return $adaptiveCard
}
Expand All @@ -128,8 +125,8 @@ function CreateExternalConnection{
[PSCustomObject] $externalConnection
)

Write-Host "Creating external connection..." -NoNewLine
New-MgExternalConnection -BodyParameter $externalConnection.connection -ErrorAction Stop | Out-Null
Write-Host "Creating external connection..." -NoNewLine -ForegroundColor Blue
New-MgExternalConnection -BodyParameter $externalConnection.connection -ErrorAction Stop
Write-Host "DONE" -ForegroundColor Green

Write-Host "Creating schema..." -NoNewLine
Expand Down Expand Up @@ -167,9 +164,14 @@ function Import-ExternalItems {
$i = 0

$ExternalItems | ForEach-Object {
Set-MgExternalConnectionItem -ExternalConnectionId $externalConnection.connection.id -ExternalItemId $_.id -BodyParameter $_ -ErrorAction Stop | Out-Null
$complete = [math]::Round((++$i/$count)*100, 0)
Write-Progress -Activity "Importing items" -Status "$complete% Complete: $($_.id)" -PercentComplete $complete
try{
Set-MgExternalConnectionItem -ExternalConnectionId $externalConnection.connection.id -ExternalItemId $_.id -BodyParameter $_ -ErrorAction Stop | Out-Null
$complete = [math]::Round((++$i/$count)*100, 0)
Write-Progress -Activity "Importing items" -Status "$complete% Complete: $($_.id)" -PercentComplete $complete
}catch{
Write-Host "Error importing item: $($_.id) $_" -ForegroundColor Red
}

}
}

Expand Down
27 changes: 17 additions & 10 deletions samples/powershell-json-ignite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ This sample contains a Microsoft Graph connector built in PowerShell that shows

![Local markdown files displayed in Microsoft Search search results](assets/screenshot.png)

# Graph connector to import markdown files into the Graph
## Graph connector to import markdown files into the Graph

This uses the sample from PnP Graph connectors as a basis for importing the content into the Graph. The original sample is here:
https://github.com/pnp/graph-connectors-samples/tree/main/samples/powershell-markdown

## Session Data

The session data was captured before the Ignite event, there maybe updates that require an update to the external items.

## Contributors

- [Paul Bullock](https://twitter.com/pkbullock)
- [Paul Bullock](https://linkedin.com/in/pkbullock)

## Version history

Version|Date|Comments
-------|----|--------
1.0|November 23, 2023|Initial release
2.0|October 30, 2024 | Ignite 2024 Sessions

## Prerequisites

- [Microsoft 365 Developer tenant](https://developer.microsoft.com/microsoft-365/dev-program)
- [Microsoft Graph PowerShell SDK](https://learn.microsoft.com/powershell/microsoftgraph/installation?view=graph-powershell-1.0)
- [Microsoft.PowerShell.SecretManagement](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.secretmanagement/?view=ps-modules)
- [Microsoft.PowerShell.SecretStore](https://learn.microsoft.com/powershell/module/microsoft.powershell.secretstore/?view=ps-modules)
- [Microsoft 365 Developer tenant](https://developer.microsoft.com/microsoft-365/dev-program?WT.mc_id=M365-MVP-5003816)
- [Microsoft Graph PowerShell SDK](https://learn.microsoft.com/powershell/microsoftgraph/installation?view=graph-powershell-1.0&WT.mc_id=M365-MVP-5003816)
- [Microsoft.PowerShell.SecretManagement](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.secretmanagement/?view=ps-modules&WT.mc_id=M365-MVP-5003816)
- [Microsoft.PowerShell.SecretStore](https://learn.microsoft.com/powershell/module/microsoft.powershell.secretstore/?view=ps-modules&WT.mc_id=M365-MVP-5003816)

> Note, this used Microsoft Graph PowerShell 2.9.1
> Note, this used Microsoft Graph PowerShell 2.24.0
## Minimal path to awesome

Expand All @@ -45,7 +50,7 @@ Version|Date|Comments
`Functions.ps1` contains supporting functions for the script, no changes are needed here to make the sample your own.
- [Create result type](https://learn.microsoft.com/microsoftsearch/manage-result-types) with default settings and the external connection you've just created
- [Create result type](https://learn.microsoft.com/microsoftsearch/manage-result-types?WT.mc_id=M365-MVP-5003816) with default settings and the external connection you've just created
- Use the `resultLayout.json` file for the Adaptive Card code
## Features
Expand All @@ -55,11 +60,13 @@ The sample illustrates the following concepts:
- script creating the Entra (Azure AD) app registration using the Microsoft Graph SDK
- create external connection including URL to item resolver to track activity when users share external links
- create external connection schema
- ingest metadata from the ignite-session.json file into search
- ingest metadata from the ignite-sessios-2024.json file into search
- visualize the external content in search results using a custom Adaptive Card
Note: after running this, you will need to manually add the search vertical to the Microsoft Search Admin Centre [Surface the data in Microsoft Search | Microsoft Learn](https://learn.microsoft.com/en-us/graph/custom-connector-sdk-sample-search?WT.mc_id=M365-MVP-5003816)
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
![](https://m365-visitor-stats.azurewebsites.net/SamplesGallery/pnp-graph-connector-powershell-json-ignite)
![](https://m365-visitor-stats.azurewebsites.net/SamplesGallery/pnp-graph-connector-powershell-json-ignite)
49 changes: 33 additions & 16 deletions samples/powershell-json-ignite/Setup-GraphConnector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
----------------------------------------------------------------------------
Created: Paul Bullock
Copyright (c) 2023
Date: 19/11/2023
Date: 29/10/2024
Disclaimer:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Expand Down Expand Up @@ -36,24 +35,24 @@ begin{
. .\Functions.ps1

$baseExternalUrl = "https://ignite.microsoft.com/en-US/sessions/"
$jsonContent = Get-Content "content\ignite-sessions.json" -Raw | ConvertFrom-Json
$entraIdDisplayName = "Paul Bullock (Ignite 2023) - connector (PowerShell)"
$secretName = "pkbignite2023powershell"
$jsonContent = Get-Content "$(Get-Location)\content\ignite-sessions-2024.json" -Raw | ConvertFrom-Json
$entraIdDisplayName = "Paul Bullock (Ignite 2024) - connector (PowerShell)"
$secretName = "pkbignite2024powershell"
}
process {

# Load the adaptive card file
$adaptiveCard = Get-AdaptiveCard

# Define the external connection and the schema for search items structure
$externalConnection = @{
userId = "d47e12f9-99f3-40ea-8870-7b39d2be92f7" # From Azure Entra ID
# The name of the connection, as it will appear in the Microsoft Search admin center
# Defines the details of the connection
connection = @{
id = "pkbignite2023sessions"
name = "PKB Ignite 2023 Sessions"
description = "Content and sessions for Ignite 2023, listing the session information from Ignite"
id = "pkbignite2024sessions"
name = "PKB Ignite 2024 Sessions"
description = "Content and sessions for Ignite 2024, listing the session information from Ignite"
activitySettings = @{
urlToItemResolvers = @(
@{
Expand All @@ -72,9 +71,9 @@ process {
searchSettings = @{
searchResultTemplates = @(
@{
id = "pkbignitepwsh"
id = "pkbignite24pwsh"
priority = 1
layout = $adaptiveCard
layout = $adaptiveCard
}
)
}
Expand Down Expand Up @@ -124,6 +123,13 @@ process {
"lastModifiedDateTime"
)
}
@{
name = "speakerNames"
type = "String"
isQueryable = "true"
isSearchable = "true"
isRetrievable = "true"
}
@{
name = "tags"
type = "StringCollection"
Expand All @@ -138,26 +144,34 @@ process {

$jsonContent | ForEach-Object {

$startDate = $_.startDateTime
$startDate = $_.lastUpdate
if ($startDate -eq $null) {
$startDate = "2023-11-15T00:00:00+00:00"
$startDate = "2024-11-19T00:00:00+00:00"
}

$sessionDate = Get-Date $startDate -Format "yyyy-MM-ddTHH:mm:ssZ"

$speakerNames = ""
if($_.speakerNames.length -gt 0){
$speakerNames = $_.speakerNames[0]
}else{
Write-Host "No Speakers" -foregroundColor Red
}


$externalItemsToAdd += @{
id = $_.sessionId
properties = @{
title = $_.title
excerpt = $_.description
url = [System.Uri]::new([System.Uri]$baseExternalUrl, $_.sessionId).ToString()
url = [System.Uri]::new([System.Uri]$baseExternalUrl, $_.sessionCode).ToString()
date = $sessionDate
sessionCode = $_.sessionCode
"[email protected]" = "Collection(String)"
tags = $_.contentArea
speakerNames = $speakerNames
}
content = @{
# TODO Future Enhancement, transcribe the video content to form part of the content, store as Markdown
value = $_.description
type = 'text'
}
Expand Down Expand Up @@ -187,14 +201,17 @@ process {
# Create Entra app
SetupGraphConnectorEntraId -secretName $secretName -displayName $entraIdDisplayName

# Initialize Graph connection
# Initialize Graph connection i.e. connect to Microsoft Graph
InitializeGraphConnection -secretName $secretName

# Create external connection
CreateExternalConnection -externalConnection $externalConnection

# Import content
Import-ExternalItems -ExternalConnection $externalConnection -ExternalItems $externalItemsToAdd

Write-Host "Please navigate to the Microsoft Search admin center to complete the setup for search verticals as a one-time task." -ForegroundColor Yellow
Write-Host "https://admin.microsoft.com/AdminPortal/Home#/MicrosoftSearch/verticals" -ForegroundColor DarkCyan
}
end{

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion samples/powershell-json-ignite/assets/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"This sample contains a Microsoft Graph connector built in PowerShell that shows how to ingest local json content. Each session is a row of data, mapped to external connection's schema and using the metadata from the JSON file. The ingested content is set to be visible to everyone in the organization."
],
"creationDateTime": "2023-11-23",
"updateDateTime": "2023-11-24",
"updateDateTime": "2024-10-30",
"products": [
"Microsoft Graph connectors",
"Microsoft Graph",
Expand Down
Binary file modified samples/powershell-json-ignite/assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 13af305

Please sign in to comment.