Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
gregjhogan / iis-debug-dump.aspx
Created February 19, 2016 16:05
IIS debug dump page
<%@ Page Language="C#" AutoEventWireup="true" Trace="true" TraceMode="SortByCategory" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET Diagnostic Page</title>
</head>
<body>
<form id="form1" runat="server">
<h2>Environment Variables</h2>
<pre>
@gregjhogan
gregjhogan / msdeploy-package-to-site.cmd
Created February 26, 2016 19:50
use msdeploy to publish a package to a website
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='\\path\to\file.zip' -dest:auto,ComputerName="https://server.domain.com:8172/msdeploy.axd?site=site.domain.com",IncludeAcls='False',AuthType='NTLM' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParam:name='ParamName',value="ParamValue" -setParam:kind='ProviderPath',scope='ContentPath',value='site.domain.com/appname'
@gregjhogan
gregjhogan / sqlcmd-test-connectivity.ps1
Last active March 23, 2016 14:54
Test SQL database connectivity
sqlcmd -S 'tcp:server,port' -d 'db_name' -Q 'SELECT 1'
@gregjhogan
gregjhogan / azure-custom-script-extension-run-as-user.ps1
Created March 31, 2016 14:03
How to run a script as a different user in an Azure VM Custom Script Extension
Enable-PSRemoting -Force
$credential = New-Object System.Management.Automation.PSCredential @(($AdminDomain + "\" + $AdminUsername), (ConvertTo-SecureString -String $AdminPassword -AsPlainText -Force))
Invoke-Command -FilePath $PSScriptRoot\setup-as-user.ps1 -Credential $credential -ComputerName localhost
@gregjhogan
gregjhogan / azure-arm-template-dump-output-variable.ps1
Last active April 1, 2016 02:08
Azure ARM template that dumps output variable value
$template = @{
'$schema' = "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
contentVersion = "1.0.0.0"
parameters = @{}
variables = @{}
resources = @(
)
outputs = @{
example = @{
value = "[resourceGroup()]"
@gregjhogan
gregjhogan / localmachine-encrypt-decrypt.ps1
Created April 1, 2016 20:44
local machine (vs user) encryption/decryption
Add-Type -Assembly System.Security
$password = "secret"
# encrypt
$encrypted = [System.Security.Cryptography.ProtectedData]::Protect([System.Text.Encoding]::UTF8.GetBytes($password), $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine)
[System.Convert]::ToBase64String($encrypted) | Out-File "password.txt" -Encoding UTF8
# decrypt
$encrypted = [System.Convert]::FromBase64String((Get-Content "password.txt"))
@gregjhogan
gregjhogan / msiexec-install.ps1
Created April 4, 2016 22:34
install msi file from powershell
$msiexecArgs = @(
'/i',
'INSTALLER.msi', // THIS CAN BE A URL!
'/quiet',
'/norestart'
)
Start-Process -FilePath msiexec -ArgumentList $msiexecArgs -NoNewWindow -Wait
@gregjhogan
gregjhogan / azure-ad-idp-direct-login-url-format
Created April 20, 2016 18:22
Single-signon URL that takes you directly to the IDP (useful for app scanning tools)
https://login.microsoftonline.com/{TENANT_ID}/oauth2/authorize?response_type=id_token&client_id={CLIENT_ID}&domain_hint={DOMAIN}&redirect_uri={REDIRECT_URI}
var HttpClient = require("./HttpClient");
var client = new HttpClient.HttpClient("test-agent");
client.get('GET', 'https://www.google.com', {}, function(err, res, content) { console.log(err); console.log(content); });
@gregjhogan
gregjhogan / azure-ps-storage-account-upload-blob.ps1
Created May 20, 2016 20:08
upload blob to storage account
$resourceGroup = ''
$storageAccount = ''
$file = ''
$container = ''
$blob = ''
$context = (Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccount).Context
Set-AzureStorageBlobContent -File $file -Container $container -Blob $blob -Context $context -Force