Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / sendmail.ps1
Created July 13, 2017 05:32
Send Email via Powershell (Simple Example)
#Configurable Variables
$EmailFrom = "[email protected]"
$EmailTo = "[email protected],[email protected]"
$Subject = "Email Subject Goes Here"
$Body = "The body of the email goes here."
$SMTPServer = "SMTP-SRV-01"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
<#
#Uncomment to use Gmail's SMTP server. Might need to change the port aboce
@jcefoli
jcefoli / copy_azure_configs.ps1
Last active July 27, 2017 22:57
Copy All AppSettings and ConnectionStrings from One Azure Webapp to Another
<#
.SYNOPSIS
Powershell Script that copies AppSettings and ConnectionStrings between from one Azure Web App to another on the same subscription
.Description
Pass the old and new resource group and webapp names to this script and it will copy the settings over seamlessly
.NOTES
Version: 1.0
Author: jcefoli
Creation Date: 7/27/2017
This script assumes you have the AzureRM Powershell modules installed, are logged into your Azure Account (Login-AzureRmAccount) and on the correct Subscription
@jcefoli
jcefoli / fix_wedding_photos.ps1
Last active August 31, 2017 15:07
Loop through images in batches of X and increase the EXIF timestamp by one minute per batch
<#
This script will loop through all numbered images in a folder and update the EXIF metadata timestamp by 1 minute for every X photos (see $BatchSize)
Setup:
-Assumes image filenames are numbered and sequential (34.jpg, 35.jpg, 36.jpg)
-Requires exiftool and assumes it's in your system Path or in the directory you execute this scrpt from.
Download it here: https://www.sno.phy.queensu.ca/~phil/exiftool/
Why:
-When I uploaded my wedding photos to Google Photos, I noticed they were out of order.
@jcefoli
jcefoli / force_logoff.ps1
Created August 31, 2017 15:04
Log off Every Windows User
$computer = $env:computername
$sessions = qwinsta /server:$computer
$sessions = $sessions[1..$($sessions.Count - 1)]
foreach ($Result in $sessions) {
$userName = $Result.Substring(19,22).Trim()
$id = $Result.Substring(41,7).Trim()
if ($userName -ne ""){
rwinsta /server:$computer $id
}
@jcefoli
jcefoli / backup_all_mysql_dbs.sh
Created October 24, 2017 22:12
Backup and Restore all MariaDB/MySQL Databases
#Take GZipped Backup of all DBs, Stored Procs and Triggers (https://stackoverflow.com/a/38527022)
#Note, if you want to shrink ibdata1, Another article recommends skipping a few DBS (https://stackoverflow.com/a/3456885)
#Backup
mysqldump -u root --all-databases --events --ignore-table=mysql.event --extended-insert --add-drop-database --disable-keys --flush-privileges --quick --routines --triggers | gzip > "all_databases.gz"
#Restore
gunzip < all_databases.gz | mysql -u root
@jcefoli
jcefoli / delete_pattern.lua
Created October 25, 2017 17:19
Redis: Delete Keys via Wildcard Pattern (Lua commandlet)
EVAL "for i, name in ipairs(redis.call('KEYS', '*YOUR_PATTERN_HERE*')) do redis.call('DEL', name, 0); end" 0
@jcefoli
jcefoli / get_stockclose.php
Last active November 4, 2017 12:14
Return Latest Numerical Stock/Mutual Fund Price from Alphavantage API in PHP
<?
#Usage http://localhost/get_stockclose.php?symbol=msft
#You need an API Key from www.alphavantage.co (update it on line 29)
#Mutual Fund data is delayed one day
#Get Symbol from query string
if (!isset($_GET['symbol'])){
echo "Ticker Symbol Missing. Make sure your requests ends in ?symbol=xyz";
exit;
}else{
@jcefoli
jcefoli / recursive_find_replace.ps1
Created January 10, 2018 17:01
Powershell Find/Replace: Recursively replace text in all *.config files in a directory using .NET
$configFiles = Get-ChildItem C:\YourDirectory *.config -Recurse
foreach ($file in $configFiles)
{
$content = [System.IO.File]::ReadAllText($file.FullName).Replace('foo','bar')
[System.IO.File]::WriteAllText($file.FullName, $content)
}
@jcefoli
jcefoli / time_elapsed.ps1
Created February 14, 2018 22:20
Time a Powershell Script
# Set Script Start Time
$StartTime = Get-Date
<#
-----------
Your script here
-----------
#>
# Set Script Finish Time and do math
040e67fa7ece009d4becef9f4d74ddb8d0986b60c8acf9a72f0647aae4c39fd407c5207f2c78b3c8bd9612dd13f7d6bc4b39b5bb91a4fdbb5fa6ddb8c120f03f22;webandtech