Skip to content

Instantly share code, notes, and snippets.

View aflyen's full-sized avatar

Are Flyen aflyen

View GitHub Profile
@aflyen
aflyen / EnableSharingForM365Group.ps1
Created April 27, 2023 12:11
Set Sharing on Microsoft 365 group in Azure AD
$Setting = Get-AzureADObjectSetting -TargetObjectId $GroupId -TargetType Groups
if ($Setting -eq $null)
{
Write-Host "`t`tCreating new policy"
$Template1 = Get-AzureADDirectorySettingTemplate | where -Property Id -Value "08d542b9-071f-4e16-94b0-74abb372e3d9" -EQ
$SettingCopy = $Template1.CreateDirectorySetting()
$SettingCopy["AllowToAddGuests"]=$True
New-AzureADObjectSetting -TargetType Groups -TargetObjectId $GroupId -DirectorySetting $SettingCopy -ErrorAction SilentlyContinue -ErrorVariable SetPolicyError
}
@aflyen
aflyen / Send-CorpSharePointGetRequest.ps1
Created December 6, 2022 21:06
Send GET request to the SharePoint API using interactive login with username and password for use with in example the Site Manager API
function Send-CorpSharePointGetRequest
{
Param(
[Parameter(Mandatory=$true)]
[string]$Url,
[Parameter(Mandatory=$true)]
[string]$UserName,
[Parameter(Mandatory=$true)]
[System.Security.SecureString]$Password,
[Parameter(Mandatory=$true)]
@aflyen
aflyen / Send-CorpSharePointPostRequest.ps1
Created December 6, 2022 21:05
Send POST request to the SharePoint API using interactive login with username and password for use with in example the Site Manager API
function Send-CorpSharePointPostRequest
{
Param(
[Parameter(Mandatory=$true)]
[string]$Url,
[Parameter(Mandatory=$true)]
[string]$UserName,
[Parameter(Mandatory=$true)]
[System.Security.SecureString]$Password,
[Parameter(Mandatory=$true)]
@aflyen
aflyen / Get-CorpGraphAccessToken.ps1
Created December 6, 2022 21:04
Get access token from AAD for app with ClientId and ClientSecret in PowerShell to be used in HTTP request
function Get-CorpMicrosoftGraphAccessToken
{
Param(
[Parameter(Mandatory=$true)]
[string]$TenantId,
[Parameter(Mandatory=$true)]
[string]$ClientId,
[Parameter(Mandatory=$true)]
[string]$ClientSecret
)
@aflyen
aflyen / Send-CorpGraphPostRequest.ps1
Created December 6, 2022 21:03
Send a POST reguest to Microsoft Graph from PowerShell
function Send-CorpMicrosoftGraphPostRequest
{
Param(
[Parameter(Mandatory=$true)]
[string]$Domain,
[Parameter(Mandatory=$true)]
[string]$AppId,
[Parameter(Mandatory=$true)]
[string]$AppSecret,
[Parameter(Mandatory=$true)]
@aflyen
aflyen / Get-CorpMicrosoft365GroupAlias.ps1
Created December 6, 2022 20:47
Get a unique Microsoft 365 Group alias for use when creating new groups in automated solutions
function Get-CorpMicrosoft365GroupAlias
{
Param(
[Parameter(Mandatory=$true)]
[string]$Alias
)
$AliasFound = $false
$Retries = 0
$UniqueAlias = $Alias
@aflyen
aflyen / FormatLocalTime.ps1
Created August 23, 2022 11:17
Format a time from UTC to local timezone in PowerShell
# Time in UTC
$StartTime = Get-Date "23.08.2022 10:15:00"
# Set timezone
$TimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("W. Europe Standard Time")
# Get time in local timezone
$StartTimeLocal = [System.TimeZoneInfo]::ConvertTimeFromUtc($StartTime, $TimeZone)
Write-Output "Start: $($StartTime) - Start, local: $($StartTimeLocal) - Timezone: $($TimeZone.DisplayName)"
@aflyen
aflyen / HideTeamifyPrompt-Alternative.ps1
Created June 20, 2022 12:00
Use PnP.PowerShell to set a property bag value to hide the Teamify dialog in modern SharePoint sites. This requires the "DenyAndAddCustomizePages" setting on the site to be temporary disabled. A more recommended approach can be found here: https://gist.github.com/aflyen/0bcf8ce02ca52cbc5ab5ab8b2a48ca8f
# Connect to the site
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/Project101"
# Temporary disable setting to allow access to the property bag
Set-PnPSite -DenyAndAddCustomizePages $false
# Set value in property bag
Set-PnPPropertyBagValue -Key "TeamifyHidden" -Value "TRUE"
# Re-enable setting to keep recommended security level
@aflyen
aflyen / HideTeamifyPrompt.ps1
Last active June 20, 2022 11:42
Use the SharePoint REST API to disable the Teamify prompt on modern sites
$SiteUrl = "https://contoso.sharepoint.com/sites/Project101"
# Connect to SPO using a interactive login
Connect-PnPOnline -Url $SiteUrl
# Invoke request to the SPO REST API
$Body = "{'siteUrl': '$($SiteUrl)'}"
Invoke-PnPSPRestMethod -Method Post -Url "/_api/GroupSiteManager/HideTeamifyPrompt" -Content $Body -Raw
# Expected response: {"odata.null":true}
@aflyen
aflyen / DisableNextStepsDialog.ps1
Last active May 25, 2022 13:49
Hide the next-steps dialog from modern team and communication sites in SharePoint Online using PowerShell and PnP.Framework
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/project101
$Web = Get-PnPWeb -Includes NextStepsFirstRunEnabled
$Web.NextStepsFirstRunEnabled = $false
$Web.Update()
Invoke-PnPQuery