Skip to content

Instantly share code, notes, and snippets.

View fatherjack's full-sized avatar
💭
doing things

fatherjack

💭
doing things
View GitHub Profile
function Compare-Array
{
param(
[array]$Ref,
[array]$Diff
)
$max = [math]::Max($Ref.Length,$Diff.Length)
for($i = 0; $i -lt $max; $i++){
@fatherjack
fatherjack / New-ToDoList
Last active August 30, 2019 10:29
Creates a really quick To Do list in a notepad file, just when you want to make some notes for things to get done today
function New-ToDo {
<#
.SYNOPSIS
Creates quick To Do list in Notepad
.DESCRIPTION
Creates quick To Do list in Notepad
.PARAMETER List
comma separated list of items to put in to do list
function Read-SQLConfigFile {
<#
.SYNOPSIS
Takes configuration file and shows features that are being set
.DESCRIPTION
Function to show what features and settings are being adjusted by the configuration file. Allows for comparison of
config files when combined with Compare-Object
.EXAMPLE
@fatherjack
fatherjack / Show-ExceptionType
Last active May 19, 2022 09:54
To find the Exception inheritence of an error
function Show-ExceptionType {
<#
.SYNOPSIS
Function to give inheritence of exception types for error handling purposes
.DESCRIPTION
Take an error and returns all InnerException types for the Error object and the error message
.PARAMETER Exception
The error exception as it occurred in your script
@fatherjack
fatherjack / ReplaceRules_SP_DIAGNOSTICS_format
Last active January 10, 2020 13:20
ReplaceRules sp_server_diagnostics formatter
=====
For VSCode extension replacerules <https://marketplace.visualstudio.com/items?itemName=bhughes339.replacerules>
This needs to be placed in the settings.json file
dont forget to add a trailing comma to the content that you find there
and also close the final curly brace correctly
=====
"replacerules.rules": {
"Format sp_diagnostics results 01": {
"find": "><",
git branch -m master main
git checkout main
git push -u origin main
now go to github.com and change the default branch ot main
created with reference to https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx
@fatherjack
fatherjack / New-CompressedFileSet
Last active July 27, 2020 19:13
When you have a set of files to email and if you zip them all the zip is too large for your email limit. Zip them into a set of zip files
<#
Zips a set of files into a set of zip files with a max size to allow emailing of zip files in size-restricted email environment.
Imagine 20 evenly sized files that need to be zipped and when compressed into a single .zip file, the file is 65MB. With an Exchange
email size limit of 15MB this cannot be sent by email. Using this function you can set a ZipSize limit of 12MB and then the output
will be 5 .zip files with a size around 12MB and one of around 5MB.
No source file will be spanned across zip files so the actual balance of zip file sizes will vary.
#>
/*
To visualise the hierarchy of SQL Server Audit Events and their parent groups
I think this was originally on the Microsoft official SQL Server Books online and it possibly still is. I can however never
find it when I need it so I have taken an adjusted version and pasted it here for easy access.
Thanks to unknown Microsoft employee that got their head around the CTE and Event relationships logic to come up with this.
*/
WITH datas (EventLevel, EventParent, EventName, EventType)
@fatherjack
fatherjack / pivottable.ps1
Created July 7, 2021 07:33
Add a pivot table to an excel file with ImportExcel powershell module
<#
Assumptions
$splatExcel is a hash table used for splatting the data into the Excel file with Export-Excel. Path is the path for the file.
The Excel file has a worksheet with the name of _BatchLoadData_ which has a single table named _BatchLoadDataTable_ in it
The data table has many columns that include _JobID_ and _Batch_
Result
A worksheet is added to the workbook called _BatchLoadPvt_ which contains the pivot table that we describe
@fatherjack
fatherjack / ParameterOptionsDemo.ps1
Created January 13, 2022 09:20
Some different parameter types and values for demonstration purposes
$scrpt1 = {
if(!(test-connection 'localhost' -Count 1 -Quiet)){return}
else{0..7 | % { "'"+(get-date).AddDays($_)+"'" }}
}
$scrpt2 = {
if((get-date).minute % 2 -eq 0){
@('Mon','Wed','Fri')}
else{
@('Tue','Thu','Sat')
}