Skip to content

Instantly share code, notes, and snippets.

@macna
macna / IIS-HTTPS-Redirect-Web.config
Created April 18, 2015 21:11
A snippet from a Microsoft Internet Information services web.config file that enables HTTP requests to be redirected to HTTPS. Requires that the rewrite module is installed.
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
@macna
macna / SilverStripe-Azure-Web.config
Last active February 23, 2016 17:32
An example web.config file for hosting the SilverStripe CMS in Microsoft Azure Websites.
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="silverstripe-cache" />
<add segment="vendor" />
<add segment="composer.json" />
<add segment="composer.lock" />
</hiddenSegments>
@macna
macna / MySQL-Backup.bat
Created April 18, 2015 21:19
A script for dumping a MySQL database to flat file, including a time/date stamp in the file name.
mysqldump <dbname> -uroot --skip-triggers > "D:\<your>\<folder>\<dbname>%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.sql"
@macna
macna / File-Cleanup.bat
Created April 18, 2015 21:22
A Microsoft Windows batch file for deleting files in a folder based on their file extension and age (.txt files older than 30 days in this example).
forfiles.exe -p C:\<your>\<folder> -m *.txt -d -30 -c "cmd.exe /C del @path""
@macna
macna / PHP-Azure-Websites.user.ini
Created April 18, 2015 21:23
A user.ini file for enabling PHP logging on a website hosted in Microsoft Azure Websites. Needs to be placed at the root of your application (D:\home\site\wwwroot\).
display_errors=On
log_errors=On
error_log = "D:\home\site\wwwroot\<your_dir>\php-errors.log"
@macna
macna / PowerShell-Windows-Server-Backup-Failure.ps1
Created April 27, 2015 09:38
PowerShell scripts for sending Windows Server Backup success/failure notifications. Using these scripts, you can create Windows scheduled tasks that are triggered on the event IDs of Windows Server Backup. For success notifications the task should be triggered on event ID '4'. For failure notifications the task should be triggered on event IDs '…
$hostname = hostname
Send-MailMessage -To admin@contoso.com -From "$hostname@contoso.com" -Priority High -SmtpServer smtp.contoso.com -Subject "$hostname - Backup Failure" -Body "A backup on $hostname has failed."
@macna
macna / PowerShell-Azure-Proxy.ps1
Created June 8, 2015 14:14
PowerShell script for connecting to Microsoft Azure when behind a forward-proxy. Requires the Microsoft Azure PowerShell commandlets.
$webclient=New-Object System.Net.WebClient
$creds=Get-Credential
$webclient.Proxy.Credentials=$creds
$cred = Get-Credential
Add-AzureAccount -Credential $cred
@macna
macna / PowerShell-CodeSigning.ps1
Created July 7, 2015 13:35
PowerShell script for signing a PowerShell script. Requires that you have a certificate in your personal store that is suitable for code signing
$cert = @(gci cert:\currentuser\my
-codesigning)[0]
Set-AuthenticodeSignature myscript.ps1 $cert
@macna
macna / PowerShell-Server-Reboot-Notification.ps1
Last active February 19, 2024 23:30
This PowerShell script sends an email notification when a server reboots. The script simply sends an email message, and is to be used on a scheduled task that is triggered at system startup.
# Get the server name
$hostName = hostname
# Define the email address to send notifications to
$toAddress = "someone@contoso.com"
# Send the notification
Send-MailMessage -To $toAddress -From "$hostName@contoso.com" -SmtpServer smtp.contoso.com -Subject "$hostName - Server Reboot" -Body "The server $hostName has rebooted."
Get-ADGroupMember -Identity "Some Group" -Recursive | Get-ADUser -Properties * | Export-Csv -Path "C:\Temp\groupdump.csv" -NoTypeInformation