Skip to content

Instantly share code, notes, and snippets.

View tostka's full-sized avatar

Todd Kadrie tostka

View GitHub Profile
@tostka
tostka / get-MultiLogTimelineToCsv.ps1
Last active April 23, 2018 15:28
1-liner script aimed at pulling all eventlog events over a specific time span, across multiple logs
$tlogs="System","Application","Lync Server" ;$tSrvr=$env:COMPUTERNAME ;$fltEvt=@{ logname=$null ; StartTime=(get-date "4/19/2018 1:00:00 PM") ; EndTime=(get-date "4/19/2018 3:40:00 PM") ; } ;$evts=$null ;$of=".\logs\ComboEvts-$($tlogs -join ',')-$($tSrvr)-SPAN-$(get-date $fltEvt.StartTime -format 'yyyyMMdd-HHmmtt')-TO-$(get-date $fltEvt.EndTime -format 'yyyyMMdd-HHmmtt').csv" ;foreach($tlog in $tlogs){ $fltEvt.logname=$tlog ; $lEvts = Get-WinEvent -computername $tSrvr -FilterHashtable $fltEvt | select TimeCreated,@{Name='Logname';Expression={$tlog}},Level,LevelDisplayName ,ProviderName,Id,Message ; $evts+=$lEvts ; "Log:$($fltEvt.logname):Evts:$(($lEvts|measure).count)/$(($evts|measure).count) Ttl" ;} ;$evts | sort TimeCreated | export-csv -path $of -notype ;$of=resolve-path $of ;"Evts exported to`n$($of)" ;
@tostka
tostka / move-MailboxesMostRecent.ps1
Last active April 23, 2018 15:29
Simple, 'Toss the most recent NN mbxs into the air & let Automatic Mailbox Provisioning redistribute them onto new dbs' script
<# -- TRIMMED GIST -- SEE FULL SCRIPT AT GITHUB FOR DETAILS
https://github.com/tostka/PowerShell/blob/master/ExchangeScripts/move-MailboxesMostRecent.ps1
-#>
$domaincontroller="DOMAINCONTROLLER" ;
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Using BatchName:$($BatchName)" ;
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Moving most recent $($Number) mailboxes" ;
if($db=get-mailboxdatabase $database -domaincontroller $domaincontroller ){
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Moving most recent $($Number) mailboxes" ;
$whatif=$true ;
$spltMbxGrant=@{
Identity="TARGETMAILBOX" ;
User="GRANTEE" ;
AccessRights="FullAccess";
whatif=$($whatif);
};
write-verbose "Running whatif test of add-MailboxPermission with following parameters" ;
$spltMbxGrant.whatif=$true ;
$spltMbxGrant | out-string ;
<# This is a code block that uses a splat to run an updating cmdlet
It uses a splat for the params, echo's the pre & post values, and the splat for the changes,
and supports whatif etc.
USAGE:
1. Update the TARGCMDLET with the real cmdlet ("set-exoOwaMailboxPolicy")
2. Update the $splat with target params for updating
3. Update the $props with an array ("PROP1","PROP2")of the prop names to be reported back (freq they match the $splat values)
4. Replace the GET-CMDLET with the real cmdlet's get-XXX variant.
5. Use $whatif=$true/$false to test and live-fire.
#>
<# TRIMMED GIST see full post at github for details #>
#*------v Function CheckSmartArray v------
function CheckSmartArray {
Write-Host -foregroundcolor green "`nChecking SmartArray on system $($env:COMPUTERNAME), controller slot $($targControllerSlot)..." ;
C:\Windows\System32\cmd.exe /c "C:\Program Files (x86)\Compaq\Hpacucli\Bin\hpacucli.exe" controller slot=$($targControllerSlot) physicaldrive all show
} ; #*------^ END Function CheckSmartArray ^------
<# TRIMMED #>
<# test mapi latency on a list of mailboxes#>
# one line follows...
get-content .\list.txt |
get-mailbox |
Test-MAPIConnectivity |
select Server, Database,Mailbox, Result,@{label="Latency(ms)";expression={($_.Latency.Milliseconds)}} |
ft -auto | out-default ;
<# all mailboxes in a site Ex10 EMS query #>
# one-line follows
get-exchangeserver |
where { $_.IsMailboxServer -eq $true -AND $_.Site -like '*SiteA*' -AND $_.admindisplayversion.major -eq 14 } |
get-mailboxdatabase |
where {$_.ReplicationType -eq "Remote"} |
get-mailbox -resultsize unlimited |
select samaccountname,DisplayName,Alias, Office,WindowsEmailAddress, @{Name='Addresses';Expression={[string]::join(";", ($_.EmailAddresses))}}, Database,ServerName,IsResource,IsLinked,IsShared, UseDatabaseQuotaDefaults,IssueWarningQuota, ProhibitSendQuota,ProhibitSendReceiveQuota, ArchiveDatabase,ArchiveGuid,ArchiveName, ArchiveQuota,ArchiveWarningQuota,WhenMailboxCreated, HasPicture,HasSpokenName,OrganizationalUnit, LegacyExchangeDN,PrimarySmtpAddress,RecipientType, RecipientTypeDetails,RequireSenderAuthenticationEnabled, SimpleDisplayName,ExchangeVersion,Name,DistinguishedName, Guid,ObjectCategory,WhenChanged,WhenCreated |
export
# 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
$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 ;
} ;
#*----------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