Skip to content

Instantly share code, notes, and snippets.

View bill-long's full-sized avatar

Bill Long bill-long

  • Microsoft
View GitHub Profile
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = "High")]
param (
[Parameter(Mandatory)]
[string]
$Server,
[Parameter(Mandatory)]
[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()]
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
@bill-long
bill-long / Get-TokenGroups.ps1
Last active December 6, 2023 19:29
Dump tokenGroups attribute and resolve the SIDs. Requires Powershell 3.0.
# Get-TokenGroups.ps1
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ParameterSetName = "DistinguishedName")]
[string]
$DistinguishedName,
[Parameter(Mandatory = $true, ParameterSetName = "SmtpAddress")]
[string]
[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())'"
Get-MailboxFolderStatistics administrator -FolderScope NonIpmRoot | Select Identity,@{Label="EntryId"; Expression={ -join ([Convert]::FromBase64String($_.FolderId) | % { $_.ToString("X2") }) }}