Skip to content

Instantly share code, notes, and snippets.

View bill-long's full-sized avatar

Bill Long bill-long

  • Microsoft
View GitHub Profile
param([string]$ExeName)
# For some reason, when a process stops the event doesn't always have the trailing e
$ExeStopName = $ExeName.Substring(0, $ExeName.Length - 1)
# Watch for process start events
$startEventQuery = New-Object System.Management.WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace WHERE ProcessName = `"$ExeName`"")
$startWatch = New-Object System.Management.ManagementEventWatcher($startEventQuery)
Register-ObjectEvent $startWatch -EventName EventArrived -SourceIdentifier "ProcessStarted"
$startWatch.Start()
@bill-long
bill-long / GetRealDefaultPFMailboxValue.ps1
Last active December 3, 2015 06:36
GetRealDefaultPFMailboxValue
# GetRealDefaultPFMailboxValue.ps1
#
# In Exchange Management Shell, DefaultPublicFolderMailbox shows a random
# value if the value is not set on the mailbox. This makes it difficult
# to determine whether this value has been set on a mailbox or not.
#
# The purpose of this script is to take a set of mailboxes and retrieve
# the actual DefaultPublicFolderMailbox value.
#
# To use this script, retrieve the mailboxes you want to process and pipe
@bill-long
bill-long / Delete-TNEFProps.ps1
Last active January 4, 2016 05:18
Delete-TNEFProps.ps1 is a script intended to fix the Exchange Public Folder Replication issue described here: http://bill-long.com/2014/01/16/public-folder-replication-fails-with-tnef-violation-status-0x00008000/
#################################################################################
#
# The sample scripts are not supported under any Microsoft standard support
# program or service. The sample scripts are provided AS IS without warranty
# of any kind. Microsoft further disclaims all implied warranties including, without
# limitation, any implied warranties of merchantability or of fitness for a particular
# purpose. The entire risk arising out of the use or performance of the sample scripts
# and documentation remains with you. In no event shall Microsoft, its authors, or
# anyone else involved in the creation, production, or delivery of the scripts be liable
# for any damages whatsoever (including, without limitation, damages for loss of business
@bill-long
bill-long / Create-LotsOfPFs.ps1
Created January 26, 2014 15:24
Powershell script to create a lot of public folders for testing.
# Create-LotsOfPFs.ps1
#
# Creates 10,000 public folders
function CreateFoldersRecursive($parentFolder)
{
$currentDepth++
for ($x = 1; $x -le $foldersPerLevel; $x++)
{
$thisFolder = New-PublicFolder ("Folder " + $x.ToString()) -Path $parentFolder.Identity.ToString()
@bill-long
bill-long / GenericDoAllPublicFoldersScript.ps1
Last active January 4, 2016 20:49
Generic script to iterate through public folders and do something via EWS. Use this as a basis for other scripts.
#################################################################################
# GenericDoAllPublicFoldersScript.ps1
#
# Generic script to do something to all public folders via EWS. Just change
# DoFolder to do what you want.
param([string]$FolderPath, [string]$HostName, [string]$UserName, [boolean]$Recurse)
#################################################################################
# Update the path below to match the actual path to the EWS managed API DLL.
@bill-long
bill-long / DumpItemSubjects.ps1
Created January 28, 2014 22:09
Display the subjects of all items in one or more mailboxes.
#########################################
# DumpItemSubjects.ps1
#
# Dumps the subjects of all items in the specified mailbox or mailboxes.
# You can specify one mailbox with -Mailbox, or specify multiple mailboxes
# by passing -InputFile and pointing to a file that contains a list of
# email addresses, one on each line.
#
# To capture the results, use Start-Transcript.
#
@bill-long
bill-long / CheckMoveMailboxAudits.ps1
Last active January 13, 2016 22:50
Find New-MoveRequest cmdlets run with a specific set of TargetDatabases
$targetDatabases = New-Object 'System.Collections.Generic.List[string]'
$targetDatabases.AddRange([string[]]@("MBDB1", "MBDB2", "MBDB3"))
Add-Type @"
using System;
public class MailboxMoveInfo {
public string Caller;
public DateTime RunDate;
public string Mailbox;
public string TargetDatabase;
@bill-long
bill-long / LogonToMailboxesViaEWS.ps1
Last active January 15, 2016 16:24
A simple demo of how to log on to a list of Exchange Server mailboxes using the credentials of the current logged on user. The mailboxes are specified in a file, where each line in the file is an smtp address of a target mailbox.
#########################################
# LogonToMailboxesViaEWS.ps1
#
param([string]$InputFile)
#########################################
# Update the path below to match the actual path to the EWS managed API DLL.
# Can be downloaded at: http://www.microsoft.com/en-us/download/details.aspx?id=42951
#
# Example:
# C:\> .\ConvertPrStartTimeEtc.ps1 000000009EC59B2B409ED001
#
# Wednesday, June 3, 2015 8:59:24 PM
param($byteString)
$bytesReversed = ""
for ($x = $byteString.Length - 2; $x -gt 7; $x-=2) { $bytesReversed += $byteString.Substring($x, 2) }
[DateTime]::FromFileTimeUtc([Int64]::Parse($bytesReversed, "AllowHexSpecifier"))
# Example:
# C:\> .\ConvertGuid DB62390413BF4DDF86D69EAC9ED013D9
#
# Guid
# ----
# 043962db-bf13-df4d-86d6-9eac9ed013d9
param([string]$guidByteString)
[byte[]]$guidBytes = @()
for ($x = 0; $x -lt $guidByteString.Length; $x+=2) { $guidBytes += [Byte]::Parse($guidByteString.Substring($x, 2), "AllowHexSpecifier") }