Skip to content

Instantly share code, notes, and snippets.

View derekmurawsky's full-sized avatar

Derek Murawsky derekmurawsky

View GitHub Profile
@derekmurawsky
derekmurawsky / forfiles.bat
Created February 25, 2014 14:43
A simple way to delete files older than X days in windows. This command is native and works as far back as server 2003.
REM Deletes files in specified path older than X days.
forfiles -p "C:\path\to\files" -s -m *.* -d -360 -c "cmd /c del @path"
REM Alternate way to do it. Deletes all files in current directory older than X days.
forfiles -s -m *.* -d -360 -c "cmd /c del @path"
@derekmurawsky
derekmurawsky / gist:8651988
Created January 27, 2014 16:35
MSSQL statement to add a user to all databases on a server as a datareader.
sp_msforeachdb 'use [?]; CREATE USER [MyDBUser] FOR LOGIN [MyDBLogin];EXEC sp_addrolemember ''db_datareader'', ''[MyDBUser]'''
@derekmurawsky
derekmurawsky / gist:7991224
Last active December 31, 2015 13:09
Show which DB backups go with which databases. By Ryan K https://gist.github.com/rkucsera, not me. Just very useful and I want to track it here.
SELECT
CONVERT(CHAR(100), SERVERPROPERTY('193199-WEB1')) AS Server,
msdb.dbo.backupset.database_name,
msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date,
msdb.dbo.backupset.expiration_date,
CASE msdb..backupset.type
WHEN 'D' THEN 'Database'
WHEN 'L' THEN 'Log'
END AS backup_type,
@derekmurawsky
derekmurawsky / gist:7873501
Created December 9, 2013 14:58
When you renew a certificate through the GoDaddy control panel, you will need to manually assign the private key to the certificate after import. This is the command to do so. From: http://support.microsoft.com/kb/889651
certutil -repairstore my "SerialNumber"
@derekmurawsky
derekmurawsky / gist:7758750
Last active December 30, 2015 01:49
There is an easier way: https://pspki.codeplex.com/discussions/567710#post1305701 Rackspace generates CSRs and Private keys as encoded text. To create a Windows compatible cert with embedded key, you need to use OpenSSL. This is the command to package them together. Originally from http://pic.dhe.ibm.com/infocenter/idshelp/v117/index.jsp?topic=%…
# CertUtil - Key must be in a .KEY file and must have the same base file name as the cert.
certutil –MergePFX certfile.cer certfile.pfx
# Old method, using OpenSSL
openssl pkcs12 -export -inkey MyCert.pem -in MyCert.crt -out MyCert.p12
@derekmurawsky
derekmurawsky / gist:7751196
Created December 2, 2013 15:31
Enable CLR in MSSQL
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
@derekmurawsky
derekmurawsky / gist:7751173
Last active December 30, 2015 00:39
Add BUILTIN\Administrators as a sysadmin is MSSQL. This was broken/fixed, depending on your POV, in newer versions of SQL server. This will restore it. Be aware, this is a security risk and was changed for a reason.
EXEC sp_grantlogin 'BUILTIN\Administrators'
EXEC sp_addsrvrolemember 'BUILTIN\Administrators','sysadmin'
@derekmurawsky
derekmurawsky / gist:7582042
Created November 21, 2013 14:03
This command line option will force outlook to rebuild folder names if they have been changed to another language... Yes, this actually happened once.
# One of the many useful command line options discussed here: http://office.microsoft.com/en-us/outlook-help/command-line-switches-for-outlook-2010-HP010354956.aspx
outlook.exe /resetfoldernames
@derekmurawsky
derekmurawsky / gist:7581990
Created November 21, 2013 13:59
Icons not displaying properly in Windows? Use this procedure to rebuild your icon cache.
From: http://www.sevenforums.com/tutorials/49819-icon-cache-rebuild.html
ie4uinit.exe -ClearIconCache
taskkill /IM explorer.exe /F
DEL "%localappdata%\IconCache.db" /A
shutdown /r /f /t 00
@derekmurawsky
derekmurawsky / gist:7553658
Last active December 28, 2015 19:58
web.config file to redirect to HTTPS, and a subdirectory. Disables HTTPS redirect for remoting layer. Redirects WWW.domain.com to https://domain.com
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Root Hit Redirect" enabled="false" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />