Skip to content

Instantly share code, notes, and snippets.

View plamber's full-sized avatar
🎯
Focusing

Patrick Lamber plamber

🎯
Focusing
View GitHub Profile
@plamber
plamber / gist:76f305b6cf847733f067ed8dff7f3528
Created October 2, 2021 04:02
Retrieve the Known Folder Move Directories from a OneDrive site
### Example on how to retrieve the Known Folder Move Directories from a OneDrive site
### This script is using PNP PowerShell to perform the activity
$url = "OneDriveUrl"
Connect-PnPOnline $url
function Get-FolderUrl ($context, $list, $valueToCheck) {
if ($list.RootFolder.Properties.FieldValues.ContainsKey($valueToCheck)) {
$item = $list.GetItemByUniqueId($list.RootFolder.Properties.FieldValues[$valueToCheck])
@plamber
plamber / gist:bac2456f1dca2bdfc51d52a02f2339fa
Last active May 15, 2021 12:07
Remove user from site collection and add a new site collection owner
$userToAdd = "<upnOfUserToAdd>"
$userToRemove = "<upnOfUserToRemove>"
$webUrl = "<spoUrl>"
$m365Status = m365 status
Write-Host $m365Status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
$m365Status = m365 status
@plamber
plamber / gist:9e78bd478d0cb07804737dc668bde0df
Last active April 23, 2021 14:07
Replace owner in a Microsoft Group
# This script replaces an owner with a different person in all Microsoft 365 Groups
$oldUser = "oldUserUpn"
$newUser = "newUserUpn"
# Parameters end
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
@plamber
plamber / gist:ac9695672f1ad6bc320aa142baf78821
Last active April 25, 2021 04:08
Replace Microsoft Group membership
# This script replaces the membership of a user with another with another for a given list of Microsoft 365 Groups
# The input file should contain the IDs of the Microsoft 365 Groups / Teams
## id
## b48b89cf-35be-441c-b290-853318dce42a
## b48b89cf-35be-441c-b290-853318dce42d
## babd731a-85e7-48e8-89c6-f96e565ee68c
## 3ebd3caf-efdd-4958-bbbf-1dd43e8c1493
## bd341f68-4f98-41e9-901a-d5a14dff49c8
$fileInput = "<PUTYOURPATHHERE.csv>"
$oldUser = "upnOfOldUser"
# assuming you are in the folder of your locally cloned fork....
git checkout main
# assuming you have a remote named `upstream` pointing to the official **office365-cli** repo
git fetch upstream
# update your local main branch to be a mirror of what's in the main repo
git pull --rebase upstream main
# switch to your branch where you are working, say "issue-xyz"
@plamber
plamber / gist:78ff5abf088038283011c93b2990e4e8
Created March 27, 2021 05:18
How do I reset my forked repository
# ensures current branch is master
git checkout main
# pulls all new commits made to upstream/master
git pull upstream main
# this will delete all your local changes to master
git reset --hard upstream/main
# take care, this will delete all your changes on your forked master
@plamber
plamber / gist:ab325d2e8cefd674f007b1194198719d
Last active April 10, 2021 03:36
Provision a Group and add members and owners
# This script provisions a Group with owners and members and Teamifies it
# The owners and members can be specified using a CSV file following this format
## upn,type
## pla@expertsinside.com,owner
## eba@expertsinside.com,member
## szu@expertsinside.com,member
# The CLI will provision the Group adding the current user as owner. You can remove this user from the owners list by using the $removeYourSelfFromOwners parameter
$importFile = "<putyourcsvhere.csv>"
@plamber
plamber / gist:c2a2f4ee4d286dddd343d78db36e6734
Last active March 20, 2021 08:18
List all Microsoft Teams team's Owners and Members
$fileExportPath = "<PUTYOURPATHHERE.csv>"
# process teams that you have joined only
$joined = $false
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
}
@plamber
plamber / gist:eb504e417412f03e86e6f9b8269ac342
Last active March 13, 2021 14:28
Delete all M365 Groups and SPO Sites in your development tenant
### Warning. Use with caution. This script deletes all M365 Groups and SPO Sites in your tenant
$devAccount = "<putyourupnhereforsecuritycheck>"
### Deletes the resources from the recyclebin. The CLI does not support this feature yet
$skipRecycleBin = $true
$m365Status = m365 status
Write-Host $m365Status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
@plamber
plamber / gist:dfbb0999646921af2bf2f603b5f36f01
Created March 10, 2021 05:16
List all site collection owners with PnP-PowerShell
$tenant = "<PutYourTenantIdHere>"
$env:ClientId = "<PUTYourAppIdHere>"
$env:ClientSecret = "<PUTYourAppSecretHere>"
$fileExportPath = "<PUTYOURPATHHERE.csv>"
Connect-PnPOnline https://$tenant-admin.sharepoint.com -ClientId $env:ClientId -ClientSecret $env:ClientSecret
$results = @()
$sites = Get-PnPTenantSite
$sites | ForEach-Object {