Skip to content

Instantly share code, notes, and snippets.

View arjancornelissen's full-sized avatar

Arjan Cornelissen arjancornelissen

View GitHub Profile
@arjancornelissen
arjancornelissen / Enable-PIMGraph.ps1
Last active July 9, 2025 13:05
Enable PIM role via the Graph PowerShell Modules
# Connect via deviceauthentication and get the TenantID and User ObjectID
Connect-MgGraph -UseDeviceAuthentication
$context = Get-MgContext
$currentUser = (Get-MgUser -UserId $context.Account).Id
# Get all available roles
$myRoles = Get-MgRoleManagementDirectoryRoleEligibilitySchedule -ExpandProperty RoleDefinition -All -Filter "principalId eq '$currentuser'"
# Get SharePoint admin role info
$myRole = $myroles | Where-Object {$_.RoleDefinition.DisplayName -eq "SharePoint Service Administrator"}
@arjancornelissen
arjancornelissen / where-objectLargeDataset.ps1
Created July 23, 2019 20:12
Where-Object on large datasets
$msolusers = Get-MsolUser -All | Select-object ObjectId, WhenCreated, LastPasswordChangeTimestamp, @{n="mfaenabled";e={$_.StrongAuthenticationMethods.Count -gt 0}}
$users = Get-AzureADUser -All $true | Select-Object ObjectId, UserPrincipalName, DisplayName, @{n="onpremDN";e={$_.ExtensionProperty.onPremisesDistinguishedName}}, CompanyName, AccountEnabled, UserType
foreach($user in $users)
{
$msoluser = $msolusers | where-object {$_.ObjectID -eq $user.ObjectID}
# do something with this data
}
@arjancornelissen
arjancornelissen / Enhanced-where-objectLargeDataset.ps1
Last active July 23, 2019 20:15
Enhanced where-object on large datalist
$msolusers = Get-MsolUser -All | Select-object ObjectId, WhenCreated, LastPasswordChangeTimestamp, @{n="mfaenabled";e={$_.StrongAuthenticationMethods.Count -gt 0}}
$users = Get-AzureADUser -All $true | Select-Object ObjectId, UserPrincipalName, DisplayName, @{n="onpremDN";e={$_.ExtensionProperty.onPremisesDistinguishedName}}, CompanyName, AccountEnabled, UserType
# Create empty array and do a foreach on every item, this takes a few seconds on 30.000 items
$msoluserArray = @{}
$i=0
$msolusers.foreach({
$msoluserArray["$($psitem.ObjectId)"] = $i
$i++
})
@arjancornelissen
arjancornelissen / Convert-MailboxAudittoDefault.ps1
Created April 3, 2019 09:38
Script to set every mailbox to use the default auditing settings from Microsoft
$mailboxes = Get-Mailbox -ResultSize Unlimited
$total = $mailboxes.Count
$count = 0
foreach($mailbox in $mailboxes){
Write-Progress -Activity "Updating auditing: $($mailbox.UserPrincipalName) ($count or $total)" -PercentComplete ($count/$total*100)
$count++
Set-Mailbox -Identity $mailbox.ExternalDirectoryObjectId -DefaultAuditSet Owner, Admin, Delegate
}
@arjancornelissen
arjancornelissen / Enable-TeamsUserTranslation.ps1
Last active January 26, 2019 20:40
Enables user translation for Microsoft Teams
# For a single Policy
Set-CsTeamsMessagingPolicy -Identity Tag:Default -AllowUserTranslation $true
# For all Policies
Get-CsTeamsMessagingPolicy | Set-CsTeamsMessagingPolicy -AllowUserTranslation $true
@arjancornelissen
arjancornelissen / Connect-SkypeforBusiness.ps1
Last active January 26, 2019 20:32
Connect to Skype for Business
Import-Module SkypeOnlineConnector
$sfbSession = New-CsOnlineSession -UserName <username>
Import-PSSession $sfbSession
$roleid = Get-PrivilegedRoleAssignment | Where-Object {$_.RoleName -eq "SharePoint Service Administrator"}
Enable-PrivilegedRoleAssignment -TicketNumber "I376524" -Reason "Handling SharePoint issue" -Duration 2 -RoleId $roleid
@arjancornelissen
arjancornelissen / SharePointOnlineUserPolicy02.ps1
Last active October 26, 2018 13:34
SharePoint Online User Policy Blog
$sites = Get-SPOSite -Limit All
foreach ($site in $sites)
{
Write-Output $site.Url
Set-SPOUser -Site $site.Url -LoginName "c:0t.c|tenant|<SharePoint Service Administrator Login Name>" -IsSiteCollectionAdmin $true
}
@arjancornelissen
arjancornelissen / SPOForceRenewalOfCT.ps1
Last active October 6, 2018 15:40
Script to force the renewal of Content Types
param
(
# give the URL of the site or when to reset for every site the admin url
[Parameter(Mandatory=$true)]
[string]$url,
# Do we need to use the weblogin
[Parameter(Mandatory=$false)]
[switch]
$useweblogin
@arjancornelissen
arjancornelissen / Calculate-ImmutableId.ps1
Last active August 27, 2018 16:56
Calculate ImmutableId
$user = Get-ADUser -Identity <username>
$ImmutableId = [System.convert]::ToBase64String($user.ObjectGUID.ToByteArray())