Skip to content

Instantly share code, notes, and snippets.

View tostka's full-sized avatar

Todd Kadrie tostka

View GitHub Profile
<# Exchange HubTransport queue snippet for dumping queued external delivery domain details,
for all hub servers in the local AD Site. (Exchange 2010 version)
Update the $probdom to a target fqdn, and run it.
#>
$probdom='badmaildelivery.com' ;
$Site=[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name ;
$Banner="== v Site:$($Site.toupper()) - MSGS QUEUED TO $($probdom) PER HUB: v ==" ;
write-host -foregroundcolor green "`n$((get-date).ToString('HH:mm:ss')):$($Banner)" ;
$hubsl=Get-ExchangeServer | where { $_.isHubTransportServer -eq $true -and $_.Site -match ".*\/$($Site)$"} | select -expand name ;
foreach($hub in $hubsl){ write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):----$($hub):" ;
<# This gist is TRIMMED to just the core pieces #>
#*------v Function Test-Port() v------
function Test-Port {
# attempt to open a port (telnet xxx.yyy.zzz nnn)
# call: Test-Port $server $port
PARAM([parameter(Mandatory=$true)] [alias("s")] [string]$Server, [parameter(Mandatory=$true)][alias("p")]
[int]$port
) ;
$ErrorActionPreference = “SilentlyContinue” ;
#check-ExchSvcStatusRpt.ps1
<# This gist is trimmed to just the core data gathering bits...
#>
#-------------------------------------------------
# do data collection here
<# trimmed #>
# Ex svcs
$svcs = (get-service -include *exchange* -computername $env:COMPUTERNAME | ?{$_.name -notmatch '^(Mimosa.*|wsbexchange)$'} | select name,DisplayName,status );
@tostka
tostka / append-x500LEDN-ToMbxEmailAddressess.ps1
Last active March 27, 2018 23:30
Exchange Script to splice in historical LEDN onto migrated mailboxes, to support reply-to etc on PST migrated email.
# append-x500LEDN-ToMbxEmailAddressess.ps1
<# key snippet from larger script...#>
if(test-path $InputCSV) {
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Loading Input file: $($InputCSV)" ;
$procMbxs=import-csv $InputCSV ;
foreach($pMbx in $procMbxs) {
if($tmbx = get-mailbox -identity "$($pMbx.WindowsEmailAddress)" -ea 0 ){
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):MATCHED:$($pMbx.WindowsEmailAddress)($($pMbx.displayname))=>TO:$($tmbx.WindowsEmailAddress)($($tmbx.displayname))" ;
<# TRIMMED GIST #>
#*----------------v Function ProcessLogs() v----------------
Function ProcessLogs {
<# TRIMMED GIST #>
write-host -ForegroundColor White ((get-date).ToString("HH:mm:ss") + ": Site: " + $SiteName)
foreach ($Hub in $Hubs) {
write-host -foregroundcolor White ("-" * 10)
# 1-line, wrapped at pipes and semi-colons for readability
$drvs="e","f","c" ; get-exchangeserver |
where{$_.isHubTransportServer -eq $true} |
foreach{
write-host $_ ;
foreach ($drv in $drvs) { if (test-path \\$_\$drv`$\scripts\) { break } } ;
copy \\SourceServer\e$\scripts\get-HT-MsgTrk-TopTraffic-LastXMin.ps1 \\$_\$drv`$\scripts\ -whatif ;
} ;
# comma-delimited server name array,
# foreach into logparser command
# Note: edit/update the logname string, to specify variant dates
# one-line follows (manually wrapped for clarity)
$CASs="US-HUBCAS1","US-HUBCAS2","US-HUBCAS3" ;
foreach ($CAS in $CASs){
write-host ("`n" + $CAS) ;
.\logparser.exe "SELECT cs(User-Agent) as Client, count(*) as Hits INTO $CAS-EWS-ALLClients.csv FROM '\\$CAS\e$\Weblogs\W3SVC1\ex130919*.log' WHERE cs-uri-stem LIKE '%/EWS/%' GROUP BY Client ORDER BY Hits DESC" -o:csv ;
}
#*----------V Comment-based Help (leave blank line below) V----------
<#
.SYNOPSIS
[NAME].ps1 - [1-LINE-DESC]
.NOTES
Written By: Todd Kadrie
Website: http://tinstoys.blogspot.com
Twitter: http://twitter.com/tostka
$Sites = "US;AU;EU" ;
$Sites=$Sites.split(";") ;
foreach ($Site in $Sites) {
write-host -foregroundcolor yellow "SITE: " $Site;
get-exchangeserver |
where { $_.Site -like "*$Site" } |
sort AdminDisplayVersion,ServerRole,Name |
select Name,ServerRole,AdminDisplayVersion ;
} ;
# Array of IIS paths, stored as semi-colon-delimited string
$LogDirs="\\US-HUBCAS1\e$\Weblogs\W3SVC1\;\\US-HUBCAS2\e$\Weblogs\W3SVC1\" ; $LogDirs=$LogDirs.split(";") ;
# constants for single & double quotes
$sQuot = [char]34 ; $sQuotS = [char]39 ;
foreach ($LogDir in $LogDirs) {
# build the log path to today's logs
$sTodaysLogsStr = $LogDir ;
# Ex2007 IIS log filename variant
#$sTodaysLogsStr += "ex" ;
# Ex2010 variant