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
Param(
[Parameter(Mandatory=$true)]
[string]$CredentialName,
[Parameter(Mandatory=$true)]
[string]$SiteUrl,
[Parameter(Mandatory=$true)]
[string]$TemplateName,
[Parameter(Mandatory=$true)]
[string]$StorageAccountName,
[Parameter(Mandatory=$true)]
# Requires Connect-MsolService connection to have made before running script
Param(
[Parameter(Mandatory = $true)]
[string]$AppPrincipalId
)
<#
Get App Principal Id
#>
$app = Get-MsolServicePrincipal -All | Where-Object -FilterScript { ($_.AppPrincipalId -eq $AppPrincipalId) }
@garrytrinder
garrytrinder / Add-PnPClientSideWebPart.ps1
Last active September 12, 2019 21:31
Due to Add-PnPClientSideWebPart cmdlet missing from the PnP PowerShell 2019 module, this script adds a Modern Web Part to a Modern Page on SharePoint Server 2019
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShell2019\3.9.1905.3\OfficeDevPnP.Core.dll"
[Reflection.Assembly]::LoadFile("C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShell2019\3.9.1905.3\OfficeDevPnP.Core.dll")
# PS> Add-PnPClientSideWebPart -Page $homepage -Component "Web Part Name"
# A PR has been raised to enable this cmdlet in the main PnP-PowerShell module for SP2019
# See https://github.com/SharePoint/PnP-PowerShell/pull/2250
Function Add-PnPClientSideWebPart(){
Param(
@garrytrinder
garrytrinder / Add-AppPackage.ps1
Last active September 30, 2019 00:42
teams-app-CD
o365 login -t password -u $(username) -p $(password)
$apps = o365 teams app list -o json | ConvertFrom-Json
$app = $apps | Where-Object { $_.externalId -eq $env:APPID}
if ($app -eq $null) {
# install app
o365 teams app publish -p $(System.DefaultWorkingDirectory)/teams-app-CI/package/teams-app.zip
} else {
# update app
o365 teams app update -i $app.id -p $(System.DefaultWorkingDirectory)/teams-app-CI/package/teams-app.zip
$manifest = Get-Content -Path $(System.DefaultWorkingDirectory)/teams-app-CI/package/teams-app/manifest.json | ConvertFrom-Json
$appId = $manifest.id
Write-Host "##vso[task.setvariable variable=appId;]$appId"
Write-Host "Set environment variable to $($env:APPID)"
o365 login -t password -u $(username) -p $(password)
app=$(o365 teams app list -o json | jq '.[] | select(.externalId == "'"$APPID"'")')
if [ -z "$app" ]; then
# install app
o365 teams app publish -p "$(System.DefaultWorkingDirectory)/teams-app-CI/package/teams-app.zip"
else
# update app
appId=$(echo $app | jq '.id')
@garrytrinder
garrytrinder / spo-themes-remove.ps1
Created October 6, 2019 22:40
Delete all custom colour themes from SharePoint
o365 login -t password -u $(username) -p $(password)
$themes = o365 spo theme list -o json | ConvertFrom-Json
$themes | ForEach-Object {
o365 spo theme remove -n $_.name --confirm
}
o365 login -t password -u $(username) -p $(password)
themes=$(o365 spo theme list -o json)
for theme in $(echo $themes | jq '.name'); do
o365 spo theme remove -n $theme --confirm
done
@garrytrinder
garrytrinder / office365-cli-graph.ps1
Last active November 5, 2019 23:46
Calling the Microsoft Graph from PowerShell Core using Office 365 CLI
pwsh -NoLogo
o365 login
$token = o365 accesstoken get -r https://graph.microsoft.com --new
$request = Invoke-WebRequest -Uri https://graph.microsoft.com/v1.0/me -Headers @{"Authorization"="Bearer $token"}
$request.Content | ConvertFrom-Json
@garrytrinder
garrytrinder / Add-AppRoleAssignment.ps1
Last active August 6, 2022 13:27
Add AppRole Assignment to Service Principal using Azure CLI
<#
.SYNOPSIS
Assign Application Role to Azure Active Directory service principal
.DESCRIPTION
This script helps assign Application Roles from existing resources to Azure Active Directory service principals, useful for assigning roles to Managed Identity service principals which cannot be performed through the Azure Portal
.PARAMETER ResourceName
The name of the service principal that has the app role that you want to assign