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 / Check-HierarchySync.ps1
Last active August 29, 2015 14:16
Check PF hierarchy synchronization on Exchange 2013
# Check-HierarchySync.ps1
$allPFs = New-Object 'System.Collections.Generic.List[string]'
$PFsPerMbx = New-Object 'System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[string]]'
$pfMailboxes = Get-Mailbox -PublicFolder
foreach ($pfMailbox in $pfMailboxes)
{
"Getting public folders from mailbox: " + $pfMailbox
$pfs = Get-PublicFolder -Recurse -Mailbox $pfMailbox.Identity | % { $_.Identity.ToString() }
@bill-long
bill-long / Find-MailboxExportTombstones.ps1
Last active August 29, 2015 14:17
Scours an ldifde tombstone dump for all objects with MailboxExport in the name, and outputs basic data for easy importing into Excel.
# Find-MailboxExportTombstones
$file = 'C:\someldiffile.txt'
Add-Type @"
using System;
public class Tombstone {
public DateTime WhenCreated;
public DateTime WhenChanged;
public Guid ObjectGuid;
$localComputerName = [Environment]::MachineName
# Monitor counter for threshold
function WaitForCounter($counter, $value, $duration)
{
"Started watching " + $counter + " to reach " + $value + " for " + $duration
$timeCounterReached = [DateTime]::MaxValue
Get-Counter -Counter $counter -Continuous |
% {
$nmcapDataFolder = 'C:\CollectedData'
$wprDataFolder = 'C:\CollectedData'
$nicToCapture = '*' # Can be a number or *
$numberOfCapFilesToKeep = 5
$localComputerName = [Environment]::MachineName
# Monitor counter for threshold
function WaitForCounter($counter, $value, $duration)
{
$nmcapDataFolder = 'C:\CollectedData'
$wprDataFolder = 'C:\CollectedData'
$wprBinary = 'C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\wpr.exe'
$procdumpBinary = 'C:\tools\sysinternals\procdump.exe'
$nicToCapture = '*' # Can be a number or *
$numberOfCapFilesToKeep = 5
$localComputerName = [Environment]::MachineName
function Log($logString)
@bill-long
bill-long / WatchADForChanges.ps1
Created April 21, 2015 21:18
Watch AD for changes
$lastHighestUSN = 0
$rootDSE = [ADSI]("LDAP://RootDSE")
$lastHighestUSN = $rootDSE.highestCommittedUSN
"Starting highest USN: " + $lastHighestUSN
$configNC = [ADSI]("LDAP://" + $rootDSE.configurationNamingContext)
while ($true)
{
$rootDSE = [ADSI]("LDAP://RootDSE")
$highestUSN = $rootDSE.highestCommittedUSN
if ($lastHighestUSN -lt 1) { $lastHighestUSN = $highestUSN }
@bill-long
bill-long / PurgeOldPerfmons.ps1
Created April 29, 2015 23:43
PurgeOldPerfmons.ps1. Attach this to a scheduled task that runs the perfmon. An alternative to fighting with Data Manager settings.
$perfLogsFolder = "C:\Perflogs"
$numberOfDirectoriesToKeep = 3
# Check to see if we need to clean up old nmcap files
$directories = new-object 'System.Collections.Generic.List[string]'
$directories.AddRange([System.IO.Directory]::GetDirectories($perfLogsFolder))
while ($directories.Count -gt $numberOfDirectoriesToKeep)
{
$oldestFileTime = [DateTime]::MaxValue
$oldestFileName = ""
@bill-long
bill-long / PurgeOldPerfmonsFiles.ps1
Created April 30, 2015 00:03
PurgeOldPerfmons - individual file version
$perfLogsFolder = "C:\Perflogs"
$numberOfDaysToKeep = 3
$dateThreshold = [DateTime]::Now.AddDays(0 - $numberOfDaysToKeep)
# Check to see if we need to clean up old nmcap files
$files = new-object 'System.Collections.Generic.List[string]'
$files.AddRange([System.IO.Directory]::GetFiles($perfLogsFolder))
$filesToDelete = new-object 'System.Collections.Generic.List[string]'
@bill-long
bill-long / ScanADContainersForSid.ps1
Last active August 29, 2015 14:27
Recursively checks the DACL on all Active Directory containers for the presence of a specified SID.
# ScanADContainersForSid.ps1
#
# Traverses the Active Directory hierarchy looking
# for a SID in the ACL on any container.
#
# Examples:
#
# .\ScanADContainersForSid DC1 S-1-5-32-544
#
# .\ScanADContainersForSid DC1 S-1-5-32-544 -ConfigContext $true -Verbose $true
# Fix-MailEnabledFromUnlinkedOutput.ps1
#
# The purpose of this script is to read the output of
# Find-UnlinkedPFProxies.ps1 and try to link those proxies
# back to their folders.
#
# This script must be run from Exchange Management Shell.
# File is required, DC is optional
# Example syntax: