diff --git a/scripts/export-data-from-microsoft-search/README.md b/scripts/export-data-from-microsoft-search/README.md new file mode 100644 index 000000000..f1d782a8d --- /dev/null +++ b/scripts/export-data-from-microsoft-search/README.md @@ -0,0 +1,72 @@ +--- +plugin: add-to-gallery +--- + +# Export data from MS Search + + +## Summary + +When working with data imported into the Microsoft Search service using Graph Connectors, it can be useful to export the data to a format of your choice for further analysis or to import it into another system. + +![Example Screenshot](assets/example.png) + +You will have to connect just as usual, then you must specify the entity type you want , the fields (if you don't know the names of the fields, you can look in the Search And Intelligence Admin Center) or export the schema using Get-PnPSearchExternalSchema +Finally you have to provide the name of the external data source (you can get this from the Search And Intelligence Admin Center) + + +# [PnP PowerShell](#tab/pnpps) + +```powershell + +$clientId = "aaaaaa-11111-222222-bbbbb-44444444" +$portalConn = Connect-PnPOnline -Url "https://contoso.sharepoint.com" -Interactive -ClientId $clientId -ReturnConnection + +$content = @{ + "Requests" = @( + @{ + "entityTypes" = @( + "externalItem" + ) + "query" = @{ + "queryString" = "*" + } + "contentSources" = @( + "/external/connections/AzureSqlConnector3" + ) + "fields"= @( + "CustomerName", + "CustomerArea", + "LocationID", + "LocationName", + "Responsible" + ) + } + ) +} + +#converting the content to json in order to use it in the Graph Explorer, which is a great way to test the queries +$json = $content | ConvertTo-Json -Depth 10 +$res = Invoke-PnPGraphMethod -Url "/v1.0/search/query" -Method Post -Content $content -Connection $portalConn + + +$hits = $res.value.hitsContainers.hits +foreach($hit in $hits) +{ + $hit.resource.properties + #do something with the data, like exporting it to a csv file +} + +``` +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] +*** + + +## Contributors + +| Author(s) | +|-----------| +| Kasper Larsen | + +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] + diff --git a/scripts/export-data-from-microsoft-search/assets/example.png b/scripts/export-data-from-microsoft-search/assets/example.png new file mode 100644 index 000000000..b0fbfd6c2 Binary files /dev/null and b/scripts/export-data-from-microsoft-search/assets/example.png differ diff --git a/scripts/export-data-from-microsoft-search/assets/preview.png b/scripts/export-data-from-microsoft-search/assets/preview.png new file mode 100644 index 000000000..8a97bf7f9 Binary files /dev/null and b/scripts/export-data-from-microsoft-search/assets/preview.png differ diff --git a/scripts/export-data-from-microsoft-search/assets/sample.json b/scripts/export-data-from-microsoft-search/assets/sample.json new file mode 100644 index 000000000..877eb8d85 --- /dev/null +++ b/scripts/export-data-from-microsoft-search/assets/sample.json @@ -0,0 +1,54 @@ +[ + { + "name": "export-data-from-microsoft-search", + "source": "pnp", + "title": "Export data from MS Search", + "shortDescription": "Shows how to export data from MS Search, in this case the entityType externalItem ", + "url": "https://pnp.github.io/script-samples/export-data-from-microsoft-search/README.html", + "longDescription": [ + "" + ], + "creationDateTime": "2024-11-11", + "updateDateTime": "2024-11-11", + "products": [ + "Graph", + "Microsoft Search" + ], + "metadata": [ + { + "key": "PNP-POWERSHELL", + "value": "2.12.0" + } + ], + "categories": [ + "Data", + "Report" + ], + "tags": [ + "Invoke-PnPGraphMethod" + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/export-data-from-microsoft-search/assets/preview.png", + "alt": "Preview of the sample Export data from MS Search" + } + ], + "authors": [ + { + "gitHubAccount": "kasperbolarsen", + "company": "", + "pictureUrl": "https://github.com/kasperbolarsen.png", + "name": "Kasper Larsen" + } + ], + "references": [ + { + "name": "Want to learn more about PnP PowerShell and the cmdlets", + "description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", + "url": "https://aka.ms/pnp/powershell" + } + ] + } +] diff --git a/scripts/spo-apply-custom-form-formatting-json/README.md b/scripts/spo-apply-custom-form-formatting-json/README.md deleted file mode 100644 index 97d9bcd20..000000000 --- a/scripts/spo-apply-custom-form-formatting-json/README.md +++ /dev/null @@ -1,177 +0,0 @@ ---- -plugin: add-to-gallery ---- - -# Sample showing how to apply a custom Form Formatting as part of your Site Provisioning - -## Summary - -From time to time your client will need a list/Content type that consist of a lot of fields and it looks awful while entering data. One option could be to replace the Edit form with a Power App but as far as I know it is not possible to deploy a Power App as part of your Provisioning. -Another option is to use Form formatting : -https://learn.microsoft.com/sharepoint/dev/declarative-customization/list-form-configuration - -Samples here: https://github.com/pnp/List-Formatting/tree/master/form-samples - -However the PnP Provisioning Engine /Schema does not yet support this kind of Form Formatting so what to do? - -Well, if in doubt just spin up an Azure Function and call it from your provisioning engine ;-) - -## Implementation - -- Open VS Code -- Create a new file -- Write a script as below, -- Change the variables to target to your environment -- Run the script. - -## Screenshot of Output - -![Example Screenshot](assets/example.png) - -# [PnP PowerShell](#tab/pnpps) -```powershell - - -#Apply Form Formatting to your site using an Azure Function -using namespace System.Net - -# Input bindings are passed in via param block. -param($Request, $TriggerMetadata) - -# Write to the Azure Functions log stream. -Write-Host "PowerShell HTTP trigger function processed a request." - -# Interact with query parameters or the body of the request. -$targetURL = $Request.Query.TargetURL -if (-not $targetURL) -{ - Write-Host " no targeturl received, aborting" - $body = "No TargetUrl received" - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body -}) - -} - -$ListName = $Request.Query.ListName -if (-not $ListName) -{ - Write-Host " no ListName received, aborting" - $body = "No ListName received" - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body -}) - -} -$JSONFileName = $Request.Query.JSONFileName -if (-not $JSONFileName) -{ - Write-Host " no JSONFileName received, aborting" - $body = "No JSONFileName received" - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body -}) - -} -$ContenttypeName = $Request.Query.ContenttypeName -if (-not $ContenttypeName) -{ - Write-Host " no ContenttypeName received, aborting" - $body = "No ContenttypeName received" - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body -}) - -} - -else -{ - - $body= " Targeturl received: $targetURL, ListName $ListName, JSONFileName $JSONFileName ,ContenttypeName : $ContenttypeName" - $clientId = $env:ClientId - $clientSecret = $env:clientSecret - - $SiteWhereTheJSONFileIsStored = "https://[YourTenant].sharepoint.com/sites/[YourSite]" #could also be a parameter if required - Connect-PnPOnline -Url $SiteWhereTheJSONFileIsStored -ClientId $clientId -ClientSecret $clientSecret - $ClientFormCustomFormatter = Get-PnPFile -Url $JSONFileName -AsString - if(-not $ClientFormCustomFormatter) - { - Write-Host " no ClientFormCustomFormatter found, aborting" - $body = "No ClientFormCustomFormatter found " - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body - }) - } - - Connect-PnPOnline -Url $targetURL -ClientId $clientId -ClientSecret $clientSecret - - $clientContext = Get-PnPContext - - $list = Get-PnPList $ListName -ErrorAction Stop - - #Get Content Type - $contentType = Get-PnPContentType -List $ListName | Where-Object { $_.Name -eq $ContenttypeName -or $_.Name -eq "Element" } - if(-not $contentType) - { - Write-Host " no contenttype found, aborting" - $body += "No contenttype found " - $HttpStatusCode = [HttpStatusCode]::BadRequest - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body - }) - } - $clientContext.Load($contentType) - $clientContext.Load($contentType.FieldLinks) - $clientContext.ExecuteQuery() - #open the ct if it is read only - if($contentType.ReadOnly) - { - $contentType.ReadOnly = $false - $contentType.Update(0) - $clientContext.ExecuteQuery() - } - - - $contentType.ClientFormCustomFormatter = $ClientFormCustomFormatter - $contentType.Update(0) - $clientContext.ExecuteQuery() - - if($contentType.ReadOnly) - { - $contentType.ReadOnly = $true - $contentType.Update(0) - $clientContext.ExecuteQuery() - } - $body += "ClientFormCustomFormatter updated for $ListName on $targetURL" - $HttpStatusCode = [HttpStatusCode]::OK -} - -# Associate values to output bindings by calling 'Push-OutputBinding'. -Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ - StatusCode = $HttpStatusCode - Body = $body -}) - -``` -[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] -*** - -## Contributors - -| Author(s) | -|-----------| -| Kasper Larsen, Fellowmind| - -[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] - diff --git a/scripts/spo-apply-custom-form-formatting-json/assets/example.png b/scripts/spo-apply-custom-form-formatting-json/assets/example.png deleted file mode 100644 index 6de63bfe8..000000000 Binary files a/scripts/spo-apply-custom-form-formatting-json/assets/example.png and /dev/null differ diff --git a/scripts/spo-apply-custom-form-formatting-json/assets/preview.png b/scripts/spo-apply-custom-form-formatting-json/assets/preview.png deleted file mode 100644 index 131807a96..000000000 Binary files a/scripts/spo-apply-custom-form-formatting-json/assets/preview.png and /dev/null differ diff --git a/scripts/spo-apply-custom-form-formatting-json/assets/sample.json b/scripts/spo-apply-custom-form-formatting-json/assets/sample.json deleted file mode 100644 index 5d4e68d6f..000000000 --- a/scripts/spo-apply-custom-form-formatting-json/assets/sample.json +++ /dev/null @@ -1,55 +0,0 @@ -[ - { - "name": "spo-apply-custom-form-formatting-json", - "source": "pnp", - "title": "Sample showing how to apply a custom Form Formatting as part of your Site Provisioning", - "shortDescription": "Sample showing how to apply a custom Form Formatting as part of your Site Provisioning using an Azure Function", - "url": "https://pnp.github.io/script-samples/spo-apply-custom-form-formatting-json/README.html", - "longDescription": [ - "Sample showing how to apply a custom Form Formatting as part of your Site Provisioning using an Azure Function" - ], - "creationDateTime": "2022-10-21", - "updateDateTime": "2022-10-21", - "products": [ - "SharePoint" - ], - "metadata": [ - { - "key": "PNP-POWERSHELL", - "value": "1.6.0" - } - ], - "categories": [ - "Data" - ], - "tags": [ - "Connect-PnPOnline", - "Get-PnPFile", - "Get-PnPContext", - "Get-PnPList", - "Get-PnPContentType" - ], - "thumbnails": [ - { - "type": "image", - "order": 100, - "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-apply-custom-form-formatting-json/assets/preview.png", - "alt": "Image from https://lightningtools.com/" - } - ], - "authors": [ - { - "gitHubAccount": "kasperbolarsen", - "pictureUrl": "https://avatars.githubusercontent.com/u/20593570?s=400&u=f9a4d5137685d8c3fcc60394fc193f3e8156f678&v=4", - "name": "Kasper Larsen" - } - ], - "references": [ - { - "name": "Want to learn more about PnP PowerShell and the cmdlets", - "description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", - "url": "https://aka.ms/pnp/powershell" - } - ] - } -]