Skip to content

Instantly share code, notes, and snippets.

@mbourgon
mbourgon / odbc_driver_version.ps1
Last active May 15, 2024 13:05
odbc driver file versions - find which version of all the drivers are installed.
#the property "DriverODBCVer" is which version of *ODBC* it supports. We have to get the file info.
#https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/how-to-correctly-check-file-versions-with-powershell/ba-p/257642
$odbc= get-odbcdriver|where {$_.name -match "sql server"}
$flat = foreach ($odbclist in $odbc){
foreach($Property in ($odbclist.attribute)){
$driverfilename = $property.driver -replace "%WINDIR%", "C:\windows\"
$driverversion = ((get-item $driverfilename).VersionInfo |select -expand Fileversion)
[pscustomobject]@{
name = ($odbclist.name)
@mbourgon
mbourgon / Teams_Full_Export.ps1
Created February 5, 2024 17:29
Teams - Full Export of your chats and messages
#Who: Michael Bourgon 2024
#What: save out all your messages/chats/meetings from Teams to HTML pages for later searching
#future fixes: change the filedate to be the time of the last message. Doubt it matters, though, since you'll be scanning this and see that it's archived.
# Requires the microsoft graph powershell module 1.27 or better.
$RequiredScopes = @("Chat.ReadBasic", "Chat.ReadWrite")
Connect-MgGraph -Scopes $RequiredScopes
$startdate = (get-date).AddDays(-3000) #because for oneOnOnes, I want a lot, and it searches for changes, not meetings with active messages - doesn't appear to be a way
$meetingchanged = (get-date).AddDays(-210) #lookback for meeting changes, only include meetings with changes more recent than this
@mbourgon
mbourgon / severity_10plus_errors_XE_memory.sql
Last active April 27, 2023 20:27
severity_10plus_errors_XE_memory
--1.1, 20191210 first version I know of
--1.2, 20230223 major changes to speed it up, after dealing with a particular server, added Azure SQL DB details.
--1.21 20230403 adding event_sequence
--1.22 20230427 adding CPID Client PID. Find app with posh: gwmi win32_process -cn theclientnamehere -filter "ProcessId=2900"
--thebakingdba.blogspot.com
/*
CREATE EVENT SESSION
severity_10plus_errors_XE_memory
ON server --use "on database" for Azure SQL DB
ADD EVENT sqlserver.error_reported
@mbourgon
mbourgon / azure_email_queue_from_onprem.ps1
Last active May 11, 2023 20:26
Azure SQL Mail sp_send_dbmail replacement with onprem - code to pull from emailqueue table, query databases, send emails with attachments++
#2022/10/17 mdb - the goal is to be able to run this on-prem and send emails from azure.
# This needs to be replaced with a function at some point, but I need email functionality right now.
# Tries to support as many of the standard parameters as possible.
#2023/01/06 mdb - adding maxcharlength at 200k to handle larger emails
#2023/01/17 mdb - handling double quotes in the query - can't use replace on a null, trying REPLACE in the initial query_to_run didn't work, wound up moving it after the null check for query block
#2023/01/19 mdb - what happens if the query is empty? No file created, so it fails. Fixed.
$ErrorActionPreference="Stop"
#First, get what's in the table to perform/mail
@mbourgon
mbourgon / ssrs_actual_datasource_info.ps1
Created January 21, 2022 21:35
SSRS - use microsoft ReportingServicesTools to walk through all datasources on a server
#What is this? Uses the microsoft tool & API & SQL Server to figure out ALL your actual datasources.
#As per the stackoverflow below, you CANNOT just use the RDLs - they don't get updated if you do it through the GUI.
#The Microsoft tool works great, but does them one at a time. So by combining the two, hopefully you get the best of both worlds.
#Note - there are two prerequisites.
#1 - invoke-sqlcmd2. Invoke/Import yourself; not doing it in here. Find on github. You might be able to use invoke-sqlcmd, but I never use it.
#2 - Microsoft's ReportingServicesTools, available on Github
#to install #2 (as of 2022): Invoke-Expression (Invoke-WebRequest https://raw.githubusercontent.com/Microsoft/ReportingServicesTools/master/Install.ps1)
$SSRS_Servername = "yourservernamehere" #assumes ReportServer for name. Aka when you go to the website, you should be able to http://yourservernamehere/ReportServer
@mbourgon
mbourgon / teams_posting_sql_as_table.ps1
Last active December 10, 2019 19:51
Queries SQL Server, and uses the HTML that it produced and pastes it to teams.
<#you can't use ACTUAL adapter cards, but you can use HTML, albeit just BODY.#>
<#Thebakingdba.blogspot.com 2019#>
. C:\Powershell_Scripts\invoke-sqlcmd2.ps1
$query = @"
DECLARE @tableHTML NVARCHAR(MAX)
, @MailSubject VARCHAR(200)
SELECT @tableHTML = '<table>'
@mbourgon
mbourgon / WAIT_AT_LOW_PRIORITY_Standard_Edition_Example.sql
Created May 7, 2019 20:58
An example proving that WAIT_AT_LOW_PRIORITY works in Standard Edition.
USE mycrappydatabase
GO
CREATE PARTITION FUNCTION pf(INT) AS RANGE LEFT FOR VALUES (5,10,15);
GO
CREATE PARTITION SCHEME ps AS PARTITION pf ALL TO ([PRIMARY]);
GO
CREATE TABLE partitionexample(id INT PRIMARY KEY) ON ps(id);
GO
INSERT dbo.partitionexample
(
@mbourgon
mbourgon / aws_RDS_email_when_PendingMaintenanceAction.ps1
Last active November 5, 2019 05:37
AWS RDS - email when there's an update to be applied via Get-RDSPendingMaintenanceAction
Remove-Variable -Name * -ErrorAction SilentlyContinue
import-module awspowershell
$myaccesskey = "youraccesskey"
$mysecretkey = "yoursecretkey"
$myregion = "yourregion"
$myemail = "youremailaddress"
$mysmtp = "smtp.yourcompany.com"
@mbourgon
mbourgon / aws_aurora_read_cloudwatch_logs.ps1
Last active May 18, 2018 18:18
AWS Aurora - reading Cloudwatch logs with Powershell for QUERYs
import-module awspowershell
# removing variables. Note that this will wipe out default region, credentials, etc, if before this line.
Remove-Variable -Name * -ErrorAction SilentlyContinue
Set-DefaultAWSRegion -Region us-west-1
$now = get-date
# For conversion from Unix Epoch
@mbourgon
mbourgon / aws_aurora_read_errorlogs.ps1
Last active May 30, 2018 20:31
AWS Aurora - reading errorlog files with Powershell
###################################################
## Reading error logs for Aurora with Powershell ##
###################################################
# 1.01 - MDB 2018/05/30 Better trapping of time; there's a lot of rows that have no datetime that I want. Also added HTML email.
# 1.02 - mdb 2018/05/30 also dealing better with the regex filter. Recommend you convert it to a NOTMATCH; too many different error types
clear
Remove-Variable -Name * -ErrorAction SilentlyContinue
$myemail="[email protected]"