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()]
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())'"
param(
[Parameter()]
[ValidateSet("NameUnknown", "NameFullyQualifiedDN", "NameSamCompatible", "NameDisplay", "NameUniqueId", "NameCanonical", "NameUserPrincipal", "NameCanonicalEx", "NameServicePrincipal", "NameDnsDomain")]
[string]
$ExtendedNameFormat = "NameSamCompatible")
$extendedNameFormats = @{
"NameUnknown" = 0
"NameFullyQualifiedDN" = 1
"NameSamCompatible" = 2
#Requires -Modules Microsoft.Graph, Microsoft.Graph.Users.Actions
Connect-MgGraph -Scopes "User.Read.All", "Mail.ReadBasic", "Mail.Read", "Mail.ReadWrite" -DeviceAuth -ContextScope Process
$userId = (Invoke-MgGraphRequest -Uri "v1.0/me")["id"]
# Only returns 10 items by default
Get-MgUserMessage -UserId $userId | ft ReceivedDateTime,Subject
# You can filter for stuff older than a certain date
Get-MgUserMessage -UserId $userId -Filter "ReceivedDateTime lt 2023-01-25" | ft ReceivedDateTime,Subject