Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
gregjhogan / wake-on-lan-magic-packet.ps1
Created May 29, 2016 21:07
Powershell WOL (wake on LAN) magic packet
$Mac = 'xx:xx:xx:xx:xx:xx'
$MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"}
[Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray * 16)
$UdpClient = New-Object System.Net.Sockets.UdpClient
$UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7)
$UdpClient.Send($MagicPacket,$MagicPacket.Length)
$UdpClient.Close()
@gregjhogan
gregjhogan / azure-o365-smtp-send.ps1
Last active May 31, 2016 17:10
Azure Office 365 SMTP send
$Cred = Get-Credential
$From = $Cred.UserName
$To = $Cred.UserName
$Body = "Hello World!"
$Subject = "O356 SMTP Test"
Send-MailMessage -To $To -Subject $Subject -Body $Body -BodyAsHtml -UseSsl -Port 587 -SmtpServer 'smtp.office365.com' -From $From -Credential $Cred
@gregjhogan
gregjhogan / disable-certificate-validation.ps1
Created May 31, 2016 17:11
Disable certificate validation in PowerShell
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
@gregjhogan
gregjhogan / arm-template-hashtable-lookup.json
Last active April 10, 2018 18:41
ARM template SKU lookup
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0",
"parameters": {
"sku": {
"type": "string",
"defaultValue": "B1"
}
},
"variables": {
@gregjhogan
gregjhogan / arm-template-convert-to-bool.json
Last active September 7, 2016 13:33
ARM template convert to bool
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0",
"parameters": {
"authActiveDirectoryClientId": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
@gregjhogan
gregjhogan / arm-template-array-lookup.json
Last active September 20, 2016 19:38
ARM template array lookup
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0",
"parameters": {
"vnet": {
"type": "string",
"defaultValue": "resource-group/vnet-name"
},
"ipAddress": {
"type": "string",
@gregjhogan
gregjhogan / iis-redirect-http-to-https-web.config
Created June 17, 2016 17:09
IIS web.config for redirecting HTTP -> HTTPS
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="redirect HTTP to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
}
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0",
"parameters": {}
}
@gregjhogan
gregjhogan / cron-node-background-job.sh
Created July 7, 2016 22:01
cron job to keep process running
#!/bin/sh
# crontab: * * * * * /{path}/{to}/{script}.sh
ps -ef | grep 'node {script}' | grep -v grep > /dev/null
if [ $? != 0 ]
then
cd /{working}/{dir}
nohup node {script} > /dev/null 2>&1 &
fi