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 / RegexFileSearch.ps1
Last active August 29, 2015 13:59
Search text files for a given regular expression. This is for when findstr won't cut it due to its limited regexp support.
param(
[Parameter(Position=0, Mandatory=$true)]
[string] $Pattern,
[Parameter(Position=1, Mandatory=$false)]
[string] $File,
[Parameter(Mandatory=$false)]
[string] $Directory,
[Parameter(Mandatory=$false)]
[string] $FileFilter,
[Parameter(Mandatory=$false)]
@bill-long
bill-long / Check1216Errors.ps1
Last active August 29, 2015 14:00
Point this to a Directory Service log in CSV format, and it counts each unique 1216 event and tells you how many times that particular type of 1216 event occurred.
param($file)
$reader = new-object System.IO.StreamReader($file)
$errorsDictionary = new-object 'System.Collections.Generic.Dictionary[string,int]'
$nextLineIsError = $false
while ($null -ne ($buffer = $reader.ReadLine()))
{
if ($nextLineIsError)
{
$nextLineIsError = $false
@bill-long
bill-long / CheckToDoSearch.ps1
Created May 30, 2014 15:33
Check search criteria on To-Do Search folder
#########################################
# GenericDoAllMailboxFoldersScript.ps1
#
param([string]$HostName, [string]$UserName, [string]$Mailbox, [string]$InputFile)
#########################################
# Update the path below to match the actual path to the EWS managed API DLL.
#
@bill-long
bill-long / Delete-Folder.ps1
Created July 4, 2014 05:58
This script uses Microsoft.Experimental.IO.dll (see http://bcl.codeplex.com/wikipage?title=Long%20Path) to delete folders which contain files where the path exceeds 260 characters. This script recursively deletes all files and folders in the specified folder.
param($folder)
$ExperimentalIOBinary = 'C:\Users\administrator\Desktop\Microsoft.Experimental.IO.dll'
[System.Reflection.Assembly]::LoadFile($ExperimentalIOBinary)
function DeleteAllFilesRecursive($path)
{
"Getting folders in folder: " + $path
$subfolders = [Microsoft.Experimental.IO.LongPathDirectory]::EnumerateDirectories($path)
foreach ($subfolder in $subfolders)
@bill-long
bill-long / Delete-Folder.ps1
Created July 9, 2014 15:32
A Powershell script to delete folders that contain files and directories exceeding the MAX_PATH limit on Windows. Requires Microsoft.Experimental.IO.dll, which can be downloaded from Codeplex: http://bcl.codeplex.com/wikipage?title=Long%20Path
param($folder)
$ExperimentalIOBinary = 'C:\Users\administrator\Desktop\Microsoft.Experimental.IO.dll'
[System.Reflection.Assembly]::LoadFile($ExperimentalIOBinary)
function DeleteAllFilesRecursive($path)
{
"Getting folders in folder: " + $path
$subfolders = [Microsoft.Experimental.IO.LongPathDirectory]::EnumerateDirectories($path)
foreach ($subfolder in $subfolders)
@bill-long
bill-long / Resolve-SIDs.ps1
Created November 19, 2014 20:17
Script for testing the reliability of SID resolution.
# Resolve-SIDs.ps1
#
# Resolve a bunch of SIDs from a text file, in a loop.
param($file)
$sids = New-Object 'System.Collections.Generic.List[string]'
$reader = New-Object System.IO.StreamReader($file)
while ($null -ne ($buffer = $reader.ReadLine()))
{
@bill-long
bill-long / CollectDataOnEvent.ps1
Last active November 23, 2016 15:22
Automate data collection on an Exchange server when a particular event is logged in the Application event log.
$dataFolder = 'C:\CollectedData'
$nicToCapture = '*' # Can be a number or *
$collectNmcap = $true
$numberOfCapFilesToKeep = 5
$collectProcdump = $false
$procdumpProcessOrPID = '1234'
$collectEventLogs = $true
$collectLdapClientTrace = $false
foreach($level in "Machine","User") {
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
# For Path variables, append the new values, if they're not already in there
if($_.Name -match 'Path$') {
$_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
}
$_
} | Set-Content -Path { "Env:$($_.Name)" }
}
#################################################################################
# RemoveProperty.ps1
#
# Removes property 0x3FC9 from public folders.
param([string]$FolderPath, [string]$HostName, [string]$UserName, [boolean]$Recurse, [boolean]$Fix)
#################################################################################
# Update the path below to match the actual path to the EWS managed API DLL.
#
@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() }