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 / batch.http
Last active July 27, 2023 07:58
example batch
POST graph.microsoft.com/v1.0/$batch
{
"requests": [
{
"url": "/me?$select=displayName,jobTitle,userPrincipalName",
"method": "GET",
"id": "1"
},
{
"url": "/me/messages?$filter=importance eq 'high'&$select=from,subject,receivedDateTime,bodyPreview",
@garrytrinder
garrytrinder / ttk_workflowbot_clean.js
Last active May 10, 2023 08:54
Script to remove the default logic in a Worfklow Bot project generated by Teams Toolkit for Visual Studio Code
// delete all files in the uploads directory
const fs = require('fs');
const path = require('path');
// clear directories
const adaptiveCards = path.join(__dirname, '../bot/src/adaptiveCards');
const cardActions = path.join(__dirname, '../bot/src/cardActions');
const comamnds = path.join(__dirname, '../bot/src/commands');
[adaptiveCards, cardActions, comamnds].forEach((dir) => {
@garrytrinder
garrytrinder / remove-apps-filtered.ps1
Last active August 21, 2023 12:43
Remove Azure AD app registrations
$notToRemove = @("app1","app2")
$apps = m365 teams app list | ConvertFrom-JSON
$apps | Where-Object { $_.displayName -notin $notToRemove } | ForEach-Object { m365 aad app remove --appId $_.appId --confirm }
@garrytrinder
garrytrinder / test.yml
Created May 2, 2022 17:25
Test workflow for CLI for Microsoft 365 Login Action
on: [workflow_dispatch]
jobs:
cli_login_job:
runs-on: ubuntu-latest
name: CLI Login Job
steps:
- name: Checkout
uses: actions/checkout@v3
- name: CLI for Microsoft 365 Login
@garrytrinder
garrytrinder / cli-microsoft365-betas.js
Last active March 12, 2022 16:56
Scrapes the npm versions page for CLI Microsoft 365 and returns betas for a specific version
var betas = []; document.querySelectorAll("a.code").forEach((version)=>{ version.innerText.includes("5.0.0-beta") ? betas.push(version.innerText); betas;
@garrytrinder
garrytrinder / extract.ps1
Last active March 10, 2022 10:42
Unpacks a Power Platform solution and unpacks the Canvas Apps contained within using Power Platform CLI
# unpack the solution
pac solution unpack --zipFile "$((Get-Location).Path)\export\solution.zip" --folder "$pwd\solution"
# extract canvas apps
$canvasapps = Get-ChildItem -Path .\solution\CanvasApps\* -Include *.msapp
$canvasapps | Foreach-Object {
pac canvas unpack --msapp $_.FullName --sources "$((Get-Location).Path)\canvasapps\$($_.Name.Split("_")[1])"
}
@garrytrinder
garrytrinder / delete-completed-todos.ps1
Created April 7, 2021 21:57
Delete completed Microsoft To Do tasks in all task lists
Write-Output "Getting Microsoft To Do task lists ..."
$lists = m365 todo list list -o json | ConvertFrom-Json
Write-Output "Iterating Microsoft To Do task lists ..."
$lists | ForEach-Object {
$listId = $_.Id
Write-Output "Getting completed tasks from '$($_.displayName)' task list ..."
$tasks = m365 todo task list --listId $listId -o json --query '[?status==`completed`]' | ConvertFrom-Json
Write-Output "$($tasks.Count) completed tasks found ..."
@garrytrinder
garrytrinder / Export-PowerAutomateFlows.ps1
Last active May 28, 2024 10:15
Exports all Power Automate Flows as ZIP files from the default environment using CLI for Microsoft 365
Write-Output "Getting environment info..."
$environment = m365 flow environment list --query '[?contains(displayName,`default`)] .name'
Write-Output "Getting Flows info..."
$flows = m365 flow list --environment $environment --asAdmin --output json | ConvertFrom-JSON
Write-Output "Found $($flows.Count) Flows to export..."
$flows | ForEach-Object {
Write-Output "Exporting as ZIP & JSON... $($_.displayName)"
@garrytrinder
garrytrinder / settings.json
Created December 19, 2020 23:55
Windows Terminal Settings
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
"copyOnSelect": false,
"copyFormatting": false,
"profiles": {
"defaults": {
"fontFace": "JetBrains Mono",
"fontSize": 12
},
@garrytrinder
garrytrinder / docker.sh
Created December 6, 2020 13:27
Execute PS1 script from host machine inside CLI for Microsoft 365 Docker container, uses custom Azure AD identity and password login
docker run --rm -it -v ${PWD}:/home/cli-microsoft365/scripts -e "CLIMICROSOFT365_AADAPPID=da049853-dd90-49df-aa21-4e0c8b646a36" -e "CLIMICROSOFT365_TENANT=e8954f17-a373-4b61-b54d-45c038fe3188" -e "[email protected]" -e "M365_PASSWORD=password" m365pnp/cli-microsoft365:next pwsh scripts/script.ps1