Skip to content

Instantly share code, notes, and snippets.

Avatar

Arjan Cornelissen arjancornelissen

View GitHub Profile
@arjancornelissen
arjancornelissen / Enhanced-where-objectLargeDataset.ps1
Last active Jul 23, 2019
Enhanced where-object on large datalist
View Enhanced-where-objectLargeDataset.ps1
$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++
})
View where-objectLargeDataset.ps1
$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 / Convert-MailboxAudittoDefault.ps1
Created Apr 3, 2019
Script to set every mailbox to use the default auditing settings from Microsoft
View Convert-MailboxAudittoDefault.ps1
$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 Jan 26, 2019
Enables user translation for Microsoft Teams
View Enable-TeamsUserTranslation.ps1
# 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 Jan 26, 2019
Connect to Skype for Business
View Connect-SkypeforBusiness.ps1
Import-Module SkypeOnlineConnector
$sfbSession = New-CsOnlineSession -UserName <username>
Import-PSSession $sfbSession
View Enable-SinglePIMRole.ps1
$roleid = Get-PrivilegedRoleAssignment | Where-Object {$_.RoleName -eq "SharePoint Service Administrator"}
Enable-PrivilegedRoleAssignment -TicketNumber "I376524" -Reason "Handling SharePoint issue" -Duration 2 -RoleId $roleid
@arjancornelissen
arjancornelissen / Update-ImmutableId.ps1
Created Aug 26, 2018
Update cloud user with the on-premises ImmutableId
View Update-ImmutableId.ps1
$aaduser = Get-AzureADUser -SearchString <Cloud username>
Set-AzureADUser -ObjectId $aaduser.ObjectId -ImmutableId $ImmutableId
View Calculate-ImmutableId.ps1
$user = Get-ADUser -Identity <username>
$ImmutableId = [System.convert]::ToBase64String($user.ObjectGUID.ToByteArray())
@arjancornelissen
arjancornelissen / Get-mailboxSize.ps1
Created Jun 25, 2018
Get Shared and resource mailbox size
View Get-mailboxSize.ps1
$mailboxes = Get-Mailbox -ResultSize unlimited -Filter {RecipientTypeDetails -eq "SharedMailbox" -or RecipientTypeDetails -eq "RoomMailbox" -or RecipientTypeDetails -eq "EquipmentMailbox"}
foreach($mailbox in $mailboxes)
{
$mailboxstats = Get-MailboxStatistics -Identity $mailbox.UserPrincipalName | Select-Object DisplayName, Identity, TotalItemSize
$mailboxsizeLine = [PSCustomObject][Ordered]@{
Identity = $mailbox.Identity
UPN = $mailbox.UserPrincipalName
DisplayName = $mailboxstats.DisplayName
TotalItemSize = $mailboxstats.TotalItemSize
@arjancornelissen
arjancornelissen / O365DNSrecords.zone
Last active Jun 17, 2018
Office 365 DNS records
View O365DNSrecords.zone
; Exchange Online
@ 3600 IN MX 0 <domain selector>.mail.protection.outlook.com.
autodiscover 3600 IN CNAME autodiscover.outlook.com.
@ 3600 IN TXT "v=spf1 include:spf.protection.outlook.com -all"
; Skype for Business
sip 3600 IN CNAME sipdir.online.lync.com.
lyncdiscover 3600 IN CNAME webdir.online.lync.com.
_sip._tls.<domain name>. 3600 IN SRV 100 1 443 sipdir.online.lync.com.
_sipfederationtls._tcp.<domain name>. 3600 IN SRV 100 1 5061 sipfed.online.lync.com.