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:4e074791ca569143210decbd3d4de686
Last active March 7, 2021 16:47
Map OneDrive folder to drive
Param(
[Parameter(Mandatory=$true)]
[string]$folderName,
[Parameter(Mandatory=$true)]
[string]$driveLetter = "Z:\"
)
New-Item "$($env:OneDrive)\$folderName" -ItemType Directory -force
$command = "subst $driveLetter ""$($env:OneDrive)\$folderName"""
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name OneDriveMapping -Value $command -PropertyType String -Force | Out-Null
@plamber
plamber / gist:2e1333bff2fcb1fa6a81545b4f9f09d1
Last active March 7, 2021 16:01
Create a Microsoft 365 Group. Assign members, a logo and Teamify it. Afterwards, create channels
$logoPath = "./pnpImage.png"
$memberDisplayName = "A"
$displayName = "Contoso Group"
$mailNickName = "demoGroup4"
$channelNames = @("Public relations", "CLI Project")
Write-Host "Creating the Group '$displayName'..."
$group = $null
$group = m365 aad o365group add --displayName $displayName `
--description "." --mailNickname $mailNickName `
@plamber
plamber / moveusersorgroupsfromthedefaultownergrouptothemembergroup.ps1
Last active February 27, 2021 05:43
Loop over all associated owner groups and assign the users of this group to the member group
$tenant = "tenantAdmin"
$adminUrl = "https://$tenant-admin.sharepoint.com"
$appId = "appId"
$appSecret = "secretKey"
$userNameOrPattern = '*'
Connect-PnPOnline $adminUrl -ClientId $appId -ClientSecret $appSecret
$tenantSites = Get-PnPTenantSite -Filter "Url -like 'prj_'"
$tenantSites = $tenantSites | Sort-Object Url -Descending
@plamber
plamber / gist:323c9bbf08f22bd839b4c4de59d08abf
Created February 22, 2021 04:57
Maniuplate existing permission levels SharePoint ONline
$tenant = "yourTenantUrl"
$adminUrl = "https://$tenant-admin.sharepoint.com"
Connect-PnPOnline $adminUrl -UseWebLogin
$tenantSites = Get-PnPTenantSite -Filter "Url -like 'prj_'"
$tenantSites = $tenantSites | Sort-Object Url -Descending
$i = 0
$total = $tenantSites.Count
@plamber
plamber / gist:18c0f6c74917eecb01491e42efd489fb
Last active April 30, 2021 00:56
Create a OneDrive folder an map it to a local drive
@echo off
set folderName=%1
set driveLetter=%2
if "%~1"=="" goto blank
echo Processing folder %folderName%...
set onedriveFolder=%OneDrive%\%folderName%
@plamber
plamber / retrieve-all-site-owners.ps1
Last active February 27, 2021 05:29
Retrieve all site collection owners using the CLI for Microsoft 365
## Get CLI for Microsoft 365 here: https://pnp.github.io/cli-microsoft365/
$fileExportPath = "<PUTYOURPATHHERE.csv>"
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
}
@plamber
plamber / gist:9d65399868c13700bdf96d2ac9db9641
Created February 16, 2021 08:39
Get all site collection admins in a tenant
$fileExportPath = "<putyourExportPathHere>"
$tenant = "<putYourTenantHere>"
$adminUrl = "https://$tenant-admin.sharepoint.com"
Connect-PnPOnline $adminUrl -UseWebLogin
# Get the site collections
$siteCollections = Get-PnPTenantSite
$results = @()
@plamber
plamber / gist:783d91bee2877afad13f2cc0abc9ed70
Last active January 28, 2021 04:08
List all tabs in Microsoft Teams teams in the tenant using CLI for Microsoft 365
## Get CLI for Microsoft 365 here: https://pnp.github.io/cli-microsoft365/
## Script inspired from https://veronicageek.com/powershell/powershell-for-m365/get-teams-channels-tabs-and-privacy-settings-using-teams-pnp-powershell/2020/07/
## Author: Patrick Lamber (https://www.nubo.eu)
$fileExportPath = "<PUTYOURPATHHERE.csv>"
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
@plamber
plamber / gist:050680ed7496312b84880fdbee1362bf
Created November 1, 2020 05:30
Search Yammer through PowerShell
$baererToken = "Put your baerer token here"
$searchQuery = "searchQuery"
$yammerBaseUrl = "https://www.yammer.com/api/v1"
Function Get-BaererToken() {
$headers = @{ Authorization=("Bearer " + $baererToken) }
return $headers
}
$headers = Get-BaererToken
@plamber
plamber / gist:c78f88d7a656268dc6305e98c3aeaf0e
Created October 22, 2020 12:42
Change the Teams Client Display Language with PowerShell
param(
[string]$locale="en-US"
)
$configPath = "$ENV:APPDATA\Microsoft\Teams\desktop-config.json";
$cookiesFilePath = "$ENV:APPDATA\Microsoft\Teams\Cookies"
$cookiesJournalPath = "$ENV:APPDATA\Microsoft\Teams\Cookies-journal"
$teams = Get-Process Teams -ErrorAction SilentlyContinue
if ($teams) {