Skip to content

Instantly share code, notes, and snippets.

View garrytrinder's full-sized avatar
👨‍💻
CLI for Microsoft 365

Garry Trinder garrytrinder

👨‍💻
CLI for Microsoft 365
View GitHub Profile
@garrytrinder
garrytrinder / m365-identity.sh
Last active October 3, 2023 12:04
Create custom Azure AD identity for use with CLI for Microsoft 365 using Azure CLI
#!/usr/bin/env zsh
function createAppRegistration (){
local appName=$1
appObjectId=`az ad app create --display-name "${appName}" --oauth2-allow-implicit-flow false --query "objectId" --output tsv`
# Undocumented: You need to create the service principal to back the app registration
# https://github.com/Azure/azure-cli/issues/12797#issuecomment-612138520
sp=`az ad sp create --id ${appObjectId}`
appId=`az ad app show --id ${appObjectId} --query "appId" --output tsv`
@garrytrinder
garrytrinder / .zshrc.sh
Last active December 19, 2020 10:40
oh-my-zsh setup
# Path to your oh-my-zsh installation.
export ZSH="/home/garrytrinder/.oh-my-zsh"
COMPLETION_WAITING_DOTS="true"
ZSH_THEME="spaceship"
SPACESHIP_PROMPT_ORDER=(
dir # Current directory section
git # Git section (git_branch + git_status)
@garrytrinder
garrytrinder / convertgif.sh
Last active September 18, 2020 19:56
Converts the given GIFs to MP4 and WEBM
#!/usr/bin/env zsh
path='../public/img/managedidentity'
files=(
"${path}/configure-logic-app"
"${path}/create-logic-app"
"${path}/enable-managed-identity"
"${path}/grant-microsoft-graph-permission"
"${path}/run-logic-app"
"${path}/view-managed-identity-service-principal"
@garrytrinder
garrytrinder / SharePointModernPageCopier.ps1
Created July 23, 2020 18:48
ModernSharePointPageCopier
# FUNCTIONS
function Set-WelcomePage {
[CmdletBinding()]
param (
# Web Url that contains the page
[Parameter(Mandatory = $true)]
[System.Uri]
$WebUrl,
# Name of the page to set
[Parameter(Mandatory = $true)]
@garrytrinder
garrytrinder / body.json
Last active July 24, 2020 22:16
Creates and configures a custom Azure AD app registration for use with the Office 365. The app registration is granted the Sites.FullControl.Read permission.
{
"isFallbackPublicClient": true,
"publicClient": {
"redirectUris": [
"https://login.microsoftonline.com/common/oauth2/nativeclient"
]
},
"web": {
"implicitGrantSettings": {
"enableIdTokenIssuance": false
@garrytrinder
garrytrinder / appreg.azcli
Created July 16, 2020 20:27
Creates Azure AD App Registration, assigns AllSites.FullControl and AllSites.Read SharePoint permissions and grants admin consent
appId=`az ad app create --display-name acms --password abcde12345 --credential-description master --required-resource-accesses @manifest.json --query "appId" --output tsv`
az ad app permission admin-consent --id ${appId}
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"eventHubName": {
"type": "string",
"metadata": {
"description": "The name of the Azure Event Hub resource"
}
},
@garrytrinder
garrytrinder / AzureFunction.sh
Created June 17, 2020 11:38
Deploys Azure Function using Azure CLI
az group create --location uksouth --name rg-dotnetfunctionlocalapponlymsi-dev
az storage account create --name stlocalapponlymsidev --resource-group rg-dotnetfunctionlocalapponlymsi-dev
az extension add --name application-insights
az monitor app-insights component create --app dotnetfunctionlocalapponlymsi --location uksouth --resource-group rg-dotnetfunctionlocalapponlymsi-dev --application-type web
az functionapp create --name func-dotnetfunctionlocalapponlymsi-dev --resource-group rg-dotnetfunctionlocalapponlymsi-dev --storage-account stlocalapponlymsidev --functions-version 3 --runtime dotnet --os-type Linux --app-insights dotnetfunctionlocalapponlymsi --consumption-plan-location uksouth
az functionapp identity assign --name func-dotnetfunctionlocalapponlymsi-dev --resource-group rg-dotnetfunctionlocalapponlymsi-dev
@garrytrinder
garrytrinder / Add-TeamFromTemplate.ps1
Created April 9, 2020 08:01
Creates a new team from a specified JSON template
$token = o365 util accesstoken get -r "https://graph.microsoft.com" --new
$template = Get-Content -Path ./template.json
$options = @{
Method = "Post"
Uri = "https://graph.microsoft.com/beta/teams"
ContentType = "application/json"
Body = $template
Headers = @{
"Authorization" = "Bearer $token";
@garrytrinder
garrytrinder / Install-TeamsAppForAllUsers.ps1
Created April 4, 2020 11:53
Install a Microsoft Teams application for all users in a tenant
[CmdletBinding()]
param (
[Parameter()]
[string]
$appName
)
$users = o365 aad user list --properties "id,displayName" -o json | ConvertFrom-Json
$app = o365 teams app list -o json | ConvertFrom-Json | Where-Object { $_.displayName -eq $AppName }