Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Enable-ExternalUserSharingOnlyOnTenantSites.ps1
Last active Nov 19, 2020
Configures all SPO site sharing settings to be ExternalUserSharingOnly (New and Existing Guests). Also removes all SharingAllowedDomainList and SharingBlockedDomainList values on each site
View Enable-ExternalUserSharingOnlyOnTenantSites.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
Import-Module SharePointPnPPowerShellOnline -WarningAction SilentlyContinue
# connect to tenant as a tenant admin
Connect-PnPOnline -Url "https://$tenant-admin.sharepoint.com" -SPOManagementShell
# find all sites that qualify to be externalized
$sites = Get-PnPTenantSite | ? LockState -eq "Unlock" | ? Url -match "/sites/" | ? Template -NotMatch "APPCATALOG|EDISC"
@joerodgers
joerodgers / Disable-ExternalSharingOnSitesWithNoGuestAccounts.ps1
Last active Nov 17, 2020
Sample that will disable the guest sharing option on all SPO sites that currently have no external external users on them.
View Disable-ExternalSharingOnSitesWithNoGuestAccounts.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
# start logging
$transcriptFile = if([string]::IsNullOrWhiteSpace($MyInvocation.MyCommand.Name)) { "Set-TeamsChannelStorageQuota.ps1" }else{ $MyInvocation.MyCommand.Name }
$transcriptPath = "$($transcriptFile)_$(Get-Date -Format FileDateTime).log"
Start-Transcript -Path $transcriptPath
# clear error history
$Error.Clear()
@joerodgers
joerodgers / BasicMetalogixUserMappingXml.ps1
Last active Nov 12, 2020
Generates the metalogix xml file using the raw LoginName and Email values for users stored in the target SharePoint site.
View BasicMetalogixUserMappingXml.ps1
Add-PSSnapin Microsoft.SharePoint.PowerShell
function ConvertTo-MetalogixUserMappingXml
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][object[]]$Mapping
)
@joerodgers
joerodgers / Reset-OneDriveStorageQuota.ps1
Last active Nov 10, 2020
Resets all OneDrive sites which have a StorageMaximumLevel less than the tenant's OneDriveStorageQuota value.
View Reset-OneDriveStorageQuota.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = "Tls11", "Tls12"
Import-Module SharePointPnPPowerShellOnline -WarningAction SilentlyContinue
# connect to the tenant
Connect-PnPOnline -Url "https://$tenant-admin.sharepoint.com" -UseWebLogin
@joerodgers
joerodgers / Get-DriveUrl.ps1
Created Nov 9, 2020
Returns the OneDrive Site Url by looking up the user in Microsoft Graph by either email address or UPN.
View Get-DriveUrl.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = "Tls11", "Tls12"
Import-Module SharePointPnPPowerShellOnline
function Get-DriveUrl
{
[cmdletbinding(DefaultParameterSetName='UserPrincipalName')]
param
(
@joerodgers
joerodgers / Get-SharePointListFlowAssociations.ps1
Created Nov 5, 2020
Kicking the tires on the new APIs for pulling Flow associations on a list in SPO as well as pulling all available Flow templates.
View Get-SharePointListFlowAssociations.ps1
Connect-PnPOnline -Url "https://m365x5551212.sharepoint.com/sites/Test" -SPOManagementShell
$ctx = Get-PnPContext
$list = Get-PnPList -Identity "Shared Documents"
$flowInstances = $list.SyncFlowInstances()
$flowTemplates = $list.SyncFlowTemplates($null)
$ctx.Load($flowTemplates)
$ctx.Load($flowInstances)
@joerodgers
joerodgers / Manage-OneDriveAdministrator.ps1
Last active Nov 19, 2020
Adds a predefined list of SCAs (user or group principals) to an OD4B site based using the email domain of the OD4B site owner and the admin lookup key.
View Manage-OneDriveAdministrator.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = "Tls11", "Tls12"
Import-Module SharePointPnPPowerShellOnline
function Remove-SiteCollectionAdministrator
{
[cmdletbinding()]
param
(
@joerodgers
joerodgers / Get-MigrationEvaluationData.ps1
Last active Oct 26, 2020
Get-MigrationEvaluationData.ps1
View Get-MigrationEvaluationData.ps1
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
function Get-LargestList
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][Microsoft.SharePoint.SPSite]$Site
)
View Manage-SiteCollectionAdmins.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
Import-Module SharePointPnPPowerShellOnline
function Remove-SiteCollectionAdministrator
{
[cmdletbinding()]
param
(
View Get-AdalSettings.ps1
function Get-AdalSettings
{
[CmdletBinding()]
param()
begin
{
$assemblies = @( "ADAL.dll", "MSO.dll", "CSI.dll" )
}
process
You can’t perform that action at this time.