Skip to content

Instantly share code, notes, and snippets.

View mercdev's full-sized avatar

Latitude17 mercdev

View GitHub Profile
@mercdev
mercdev / iis-bindings.ps1
Created May 2, 2015 23:02
Displays IIS Website configuration information
function Pause ($Message="Press any key to continue...")
{
# The ReadKey functionality is only supported at the console (not in the ISE)
if ($PGSE -eq $null)
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
@mercdev
mercdev / iis-applications.ps1
Created May 2, 2015 23:04
Displays Applications configured in IIS
# note: requires Web Administration (IIS) Provider for Windows PowerShell
# http://technet.microsoft.com/en-us/library/ee909471(v=ws.10).aspx
cls
try
{
Import-Module WebAdministration
#Get-WebApplication
@mercdev
mercdev / audit.ps1
Created May 2, 2015 23:08
PowerShell Windows AD Inventory with Excel output
# Usage: Audit.ps1 'pathtolistofservers' #
# The file is optional and needs to be a plain text list of computers to be audited one on each line. #
#
param([string] $auditlist)
cls
$Error.Clear() # clear the stack
$targets = $null
if ($auditlist -eq "")
@mercdev
mercdev / multi-deploy.ps1
Last active August 29, 2015 14:20
Multithreaded file copy (via Robocopy) to multiple destinations
cls
$source = "\\sourcefiles\path\here";
$auth = "\\authserver\c$\Fileroot";
$destDev = "\\devserver\C$\FileRoot";
$destTest = "\\testserver\C$\FileRoot";
$destStage = "\\stageserver\C$\FileRoot";
$destProd = "\\productionserver\C$\FileRoot";
#$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S /NC /NS /NDL /NJH /NJS /NFL }
$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S }
private void SetKeepAliveIOControl(Socket socket, uint interval, uint retryInterval, bool enabled)
{
int size = sizeof(UInt32);
uint on = enabled ? (uint)1 : (uint)0;
byte[] inArray = new byte[size * 3];
Array.Copy(BitConverter.GetBytes(on), 0, inArray, 0, size);
Array.Copy(BitConverter.GetBytes(interval), 0, inArray, size, size);
Array.Copy(BitConverter.GetBytes(retryInterval), 0, inArray, size * 2, size);
socket.IOControl(IOControlCode.KeepAliveValues, inArray, null);
}
param([parameter(Mandatory=$true,HelpMessage="Server Environment")]$state,$env)
Import-Module WebAdministration;
switch ($env)
{
"### SERVERNAME ###"
{
if ($state -eq "STOP")
{
DECLARE @SQL VARCHAR(MAX)
DECLARE @SearchString VARCHAR(100)
SET @SQL = ''
SET @SearchString = 'some string here'
SELECT @SQL = @SQL + 'SELECT CONVERT(VARCHAR(MAX),COUNT(*)) + '' matches in column ''+'''
+ C.name + '''+'' on table '' + ''' + SC.name + '.' + T.name +
''' [Matches for '''+@SearchString+''':] FROM ' +
QUOTENAME(SC.name) + '.' + QUOTENAME(T.name) + ' WHERE ' + QUOTENAME(C.name) +
@mercdev
mercdev / remote-iis.ps1
Created September 11, 2015 20:48
Remote IIS info via PowerShell
$website = 'Default'
$server = 'SOME_SERVER_01'
$session = New-PSSession -ComputerName $server -Name "My_Session_Name"
$remoteOriginalFolder = Invoke-Command -Session $session -ScriptBlock { param($website)
Import-Module WebAdministration
$originalFolder = Get-WebFilePath IIS:\Sites\$website
return $originalFolder.FullName
} -ArgumentList $website
$remoteOriginalFolder
@mercdev
mercdev / queue-tfs-builds.ps1
Last active November 30, 2015 14:19
Queue all enabled builds in TFS via PowerShell
cls
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$serverName = "http://server.fqdn:8080/tfs"
$teamProject = "project_name"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefinitions = $buildServer.QueryBuildDefinitions($teamProject).Name
@mercdev
mercdev / dynamic-appender.cs
Last active December 23, 2015 15:55
Creates a log4Net RollingFileAppender.
// Init: Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
// hierarchy.Root.AddAppender(CreateWSMFileAppender("logger-name-here"));
// Usage: var wsmLog = LogManager.GetLogger("logger-name-here");
// if (wsmLog != null)
// {
// wsm.InfoFormat("Hi, you did it dynamically!");
// {
private static IAppender CreateFileAppender(string appenderName)
{