Skip to content

Instantly share code, notes, and snippets.

View Timberfang's full-sized avatar

Timberfang

  • 16:16 (UTC -05:00)
View GitHub Profile
@Timberfang
Timberfang / Installer-Template.ps1
Last active June 5, 2022 19:48
Copy files from one folder to another. In the event of conflicting files, .bak will be added to the end of the file. Uninstaller reverses the installer.
Set-StrictMode -Version 3
# Make sure to fill in $source and $dest before use.
$source =# source-directory
$dest =# destination-directory
Get-ChildItem -Path $source -Recurse | ForEach-Object {
If ((Test-Path $dest\$_) -and !(Test-Path $dest\$_.bak)) {Rename-Item $dest\$_ -NewName "$_.bak" }
}
Copy-Item $source\* -Destination $dest
@Timberfang
Timberfang / Group-Item.ps1
Last active August 5, 2022 20:38
Function to rename and organize files.
Set-StrictMode -Version 3.0
#Requires -Version 5.1
function Group-Item {
<#
.SYNOPSIS
Rename and organize files.
.DESCRIPTION
Rename files to a given name, followed by a four digit number.
The original files will be moved to a folder titled "originals".
@Timberfang
Timberfang / Invoke-Mogrify.ps1
Last active August 22, 2022 12:24
Convert images to other formats using ImageMagick.
Set-StrictMode -Version 3.0
#Requires -Version 5.1
Function Invoke-Mogrify {
<#
.SYNOPSIS
Convert images to other formats using ImageMagick.
.DESCRIPTION
This function will convert given images into the specified format.
The converted images will be saved to the same location as the original images by default.
@Timberfang
Timberfang / Get-TimeSpan.ps1
Created August 3, 2022 14:51
Simple wrapper for New-TimeSpan
Set-StrictMode -Version 3.0
#Requires -Version 3.0
[int]$Hours = Read-Host -Prompt "Enter the number of hours"
[int]$Minutes = Read-Host -Prompt "Enter the number of minutes"
[int]$Seconds = Read-Host -Prompt "Enter the number of seconds"
if(-not($Hours)){
$Hours = 0
}
if(-not($Minutes)){
@Timberfang
Timberfang / Find-Numbers.ps1
Last active May 15, 2023 16:05
Find missing numbers in a list of file names.
Set-StrictMode -Version 3.0
#Requires -Version 7.0
# Find missing numbers in a list of file names containing four digit numbers in parentheses.
# Outputs list of missing numbers to pipeline.
[System.Int32[]]$Iteration = Get-ChildItem $Path | Where-Object{$_.Name -match "\(\d{4}\)"} | ForEach-Object{$Matches[0]}
$Iteration[0]..$Iteration[-1] | Where-Object{$_ -notin $Iteration}
@Timberfang
Timberfang / Rename-ToPattern.ps1
Created August 11, 2022 02:50
Rename files to match the pattern of a name, followed by a four digit number in parentheses.
Set-StrictMode -Version 3.0
#Requires -Version 5.1
# Rename files to match the pattern of a name, followed by a four digit number in parentheses.
# Example: "Test (0001)", "Test (0002)".
[string]$Name = Read-Host -Prompt "What name would you like the files to follow?"
[string]$Destination = Read-Host -Prompt "Where are the files you would like to rename?"
[string]$Extension = ( $Value = Read-Host -Prompt "What extension should the script search for? Leave this blank to rename all." ) ? $Value : '*'
@Timberfang
Timberfang / New-Launcher.ps1
Last active December 9, 2022 23:00
For each PowerShell script in the scripts directory, create a shortcut or batch file to run the script with a double click.
#Requires -Version 5.1
Set-StrictMode -Version 3.0
function New-Launcher {
[CmdletBinding()]
param(
[Parameter()]
[ValidateSet('CMD','Shortcut')]
[string]$Type = 'CMD',
@Timberfang
Timberfang / Get-DriveInfo.ps1
Last active December 11, 2022 19:47
Get a percentage of how full your storage drives are.
Set-StrictMode -Version 3.0
#Requires -Version 5.1
# Get used space on a drive, then warn if storage usage exceeds 65%.
function Get-DriveInfo {
[CmdletBinding()]
param(
$InformationPreference= "Continue",
[int]$WarnPercent = '75'
@Timberfang
Timberfang / Convert-Units.ps1
Created December 10, 2022 15:12
Convert units of length, weight, and temperature.
function Convert-Distance {
<#
.SYNOPSIS
Convert units of distance from metric to imperial and vise versa.
.DESCRIPTION
Convert units of distance from the input unit to the output unit. Supported units are the millimetre (mm), centimetre (cm), metre (m), kilometre (km), inch (in), foot (ft),
yard (yd), and mile (mi).
.PARAMETER Value
@Timberfang
Timberfang / Get-Release.ps1
Last active May 29, 2023 12:12
Download a GitHub release asset from a list stored in a csv file.
#Requires -Version 5.1
#Requires -Modules PowerShellForGitHub,PSMenu
Set-StrictMode -Version 3.0
$InformationPreference = 'Continue'
function Get-PrivateRelease {
<#
.SYNOPSIS
Download a release from a GitHub repository.