Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / BusinessDaysUntil.cs
Created February 14, 2017 07:10
Calculate the number of business days between two dates
/// <summary>
/// Calculates number of business days, taking into account:
/// - weekends (Saturdays and Sundays)
/// - bank holidays in the middle of the week
/// </summary>
/// <param name="firstDay">First day in the time interval</param>
/// <param name="lastDay">Last day in the time interval</param>
/// <param name="bankHolidays">List of bank holidays excluding weekends</param>
/// <returns>Number of business days during the 'span'</returns>
public static int BusinessDaysUntil(this DateTime firstDay, DateTime lastDay, params DateTime[] bankHolidays)
@timgaunt
timgaunt / List Product Data.sql
Created February 20, 2017 18:17
List uCommerce product data in an importable format
USE MarkerTechV2CMS
GO
WITH Fields
AS
(
SELECT
pd.ProductDefinitionId [ChildDefinitionID]
, pd.ProductDefinitionId
, pd.Name AS [ProductDefinitionName]
function Compress-Subfolders
{
param
(
[Parameter(Mandatory = $true)][string] $InputFolder,
[Parameter(Mandatory = $true)][string] $OutputFolder
)
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw "$env:ProgramFiles\7-Zip\7z.exe needed"}
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
@timgaunt
timgaunt / combine.ps1
Created March 7, 2018 07:12
Combine multiple csv or txt files together into one
$getFirstLine = $true;get-childItem "*.csv" | foreach {$filePath = $_;$lines = $lines = Get-Content $filePath;$linesToWrite = switch($getFirstLine) {$true {$lines}; $false {$lines | Select -Skip 1}};$getFirstLine = $false;Add-Content "combined.csv" $linesToWrite;}
@timgaunt
timgaunt / IIS.ps1
Last active August 10, 2018 19:30
List the IIS sites using PowerShell
Get-WebBinding | % {
$name = $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1'
New-Object psobject -Property @{
Name = $name
Binding = $_.bindinginformation.Split(":")[-1]
}
} | Group-Object -Property Name |
Format-Table Name, @{n="Bindings";e={$_.Group.Binding -join "`n"}} -Wrap
@timgaunt
timgaunt / Move Files Using List Single Line.ps1
Last active May 8, 2018 08:55
Powershell to move from one folder to another based on file list
$file_list = Get-Content "C:\files.txt"
$search_folder = "C:\from"
$destination_folder = "C:\to"
foreach ($file in $file_list) { $file_to_move = Get-ChildItem -Path $search_folder -Filter $file -Recurse -ErrorAction SilentlyContinue -Force | % { $_.FullName};if ($file_to_move) { Move-Item $file_to_move $destination_folder; } }
@timgaunt
timgaunt / IIS 32bit mode.ps1
Created May 21, 2018 05:05
Update all IIS app pools to run in 32bit mode
Import-Module WebAdministration
foreach ($webapp in Get-ChildItem -Path IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = $item = Get-Item $name | Select -ExpandProperty enable32BitAppOnWin64
if ($webapp.enable32BitAppOnWin64 -ne 'True')
{
Set-ItemProperty -Path $name -Name enable32BitAppOnWin64 -Value True
Write-Host "$name updated to enable 32bit" -ForegroundColor Yellow
@timgaunt
timgaunt / Swear Words.txt
Created October 10, 2018 17:12
List of swear words
anus
arse
arsehole
ass
ass-hat
ass-jabber
ass-pirate
assbag
assbandit
assbanger
@timgaunt
timgaunt / List Products.sql
Created May 16, 2019 11:19
List all Ucommerce products with their properties
DECLARE @cols AS NVARCHAR(MAX), @nullLessCols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX);
SET @cols = STUFF((
SELECT ',' + QUOTENAME(pdf.Name)
FROM uCommerce_ProductDefinitionField AS pdf
WHERE pdf.Deleted=0
ORDER BY pdf.SortOrder
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)'),1,1,'')
@timgaunt
timgaunt / MoveFiles.ps1
Created November 30, 2020 11:52
Move files matching a list of strings from one folder to another
$sourceFolder = "C:\"
$targetFolder = "C:\"
$regnos = @(
"regno"
)
Write-Host "Folder: $sourceFolder"
$folderFiles = Get-ChildItem -Path $sourceFolder -Filter *.jpg -Recurse -File -Name
foreach ($r in $regnos)