Skip to content

Instantly share code, notes, and snippets.

View bill-long's full-sized avatar

Bill Long bill-long

  • Microsoft
View GitHub Profile
@bill-long
bill-long / ManagePublicFolderPermissions.ps1
Created October 15, 2025 04:01
For exporting and importing PF permissions. See notes in the comment at the bottom.
<#
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
# Get-NamedProperties
#
# Example:
# .\Get-NamedProperties.ps1 -Mailbox user1 | ft Prop*
[CmdletBinding()]
param (
[Parameter()]
[string]
$Mailbox
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[int]$MaxRetries = 20,
[Parameter(Mandatory = $false)]
[string]$LogFilePath = "$PSScriptRoot\GetAllPFStatistics.log"
)
function WriteHostAndLog($message) {
# Public folder hierarchy and statistics retrieval options
## Test scenario
#
# PF mailboxes in Exchange Online.
#
# ❯ Get-PublicFolder -Mailbox MB1 -ResidentFolders -Recurse -ResultSize Unlimited | Measure | Select Count
#
# Count
# -----
@bill-long
bill-long / Get-MailboxPermissionsDetailed.ps1
Last active January 18, 2024 20:22
Useful when Get-MailboxPermissions is showing numeric rights. This script parses the msExchMailboxSecurityDescriptor and adds a Rights member which shows which valid rights are set and which invalid ones are set.
# Example:
# .\Get-MailboxPermissionsDetailed.ps1 -Alias bilong | ft SecurityIdentifier,AceQualifier,AccessMask,Rights
[CmdletBinding()]
param (
[Parameter()]
[string]
$Alias
)
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = "High")]
param (
[Parameter(Mandatory)]
[string]
$Server,
[Parameter(Mandatory)]
[string]
$Mailbox,
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Server,
[Parameter(Mandatory)]
[string]
$To,
function Get-ExchangeServices {
$services = @(Get-Service MSExchange* | Where-Object { $_.StartType -eq "Automatic" })
$services += Get-Service HostControllerService
$services += Get-Service W3SVC
return $services
}
function Stop-ExchangeServices {
$servicesToStop = Get-ExchangeServices
foreach ($service in $servicesToStop) {
# Useful for doing MCDB stuff in a lab
$action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument '-Command "Get-PhysicalDisk | Set-PhysicalDisk -MediaType SSD"'
$trigger = New-ScheduledTaskTrigger -AtStartup
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName "Set Media Type" -Action $action -Trigger $trigger -Principal $principal
[CmdletBinding()]
param (
[Parameter()]
[string]
$Mailbox
)
$mb = Get-Mailbox $Mailbox
. $exscripts\ManagedStoreDiagnosticFunctions.ps1
$mbTableResult = Get-StoreQuery -Database "$($mb.Database.ToString())" -Query "SELECT MailboxNumber FROM Mailbox WHERE MailboxGuid = '$($mb.ExchangeGuid.ToString())'"