Skip to content

Instantly share code, notes, and snippets.

View wgv-zbonham's full-sized avatar

Zach Bonham wgv-zbonham

  • WatchGuard Video
  • Allen, TX
View GitHub Profile
.\New-SelfSignedCertificateEx
function MakeCert() {
Write-Verbose("Creating deployment certificate")
New-SelfsignedCertificateEx -Subject "CN=${ENV:ComputerName}" -EKU 'Document Encryption' -KeyUsage 'KeyEncipherment, DataEncipherment'-SAN ${ENV:ComputerName} -FriendlyName 'WatchGuard Video Deployment Encryption Certificate' -Exportable -StoreLocation 'LocalMachine' -KeyLength 2048 -ProviderName 'Microsoft Enhanced Cryptographic Provider v1.0' -AlgorithmName 'RSA' -SignatureAlgorithm 'SHA256'
# Locate the newly created certificate
$Cert = Get-ChildItem -Path cert:\LocalMachine\My `
| Where-Object {
@wgv-zbonham
wgv-zbonham / Get-WgvDotNetVersion.ps1
Created September 6, 2016 16:09
Get-WgvDotNetVersion
# see https://blogs.msdn.microsoft.com/dotnet/2015/12/09/support-ending-for-the-net-framework-4-4-5-and-4-5-1/
#
param($computer=[environment]::MachineName)
Write-Debug "Get-WgvDotNetVersion($computer)"
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
@wgv-zbonham
wgv-zbonham / EvidenceLibrary-MaintenancePlan.sql
Created June 29, 2016 14:29
Evidence Library DB Maintenance Plan
use WGEvidenceLibrary
go
/*** ACTIONS BEING PERFORMED IN ORDER
1. REBUILD INDEXES
2. TRUNCATED LOG FILE
3. SHRINK DATABASE
4. UPDATE STATISTICS
5. UPDATE AUTOGROWTH SETTINGS
@wgv-zbonham
wgv-zbonham / Readme.md
Last active June 4, 2016 15:38
Managing Performance Counters

The attached counter set is just the ‘System Performance’ template with ‘Logical Disk’ counters added. The sample interval has been changed to 15 seconds. The counters are collected at c:\perflogs\admin\EL4. You need to be running under an account that is in the Administrator role for servers we are publishing counter sets to.

The perfmon template, el4perf.xml, is assumed to be in the current working directory.

From an administrator PowerShell command prompt:

To publish this counter set to a server:

logman import –n EL4 –xml .\el4perf.xml –s SERVERNAME
@wgv-zbonham
wgv-zbonham / Print-WgvDbVersion.ps1
Last active June 14, 2016 21:09
Print-WgvDbVersion
param([int]$databaseVersion)
<#
.SYNOPSIS
Converts Database Version [int] to human readable string.
.DESCRIPTION
Converts Database Version [int] to human readable string.
build = value & 0x0fff
@wgv-zbonham
wgv-zbonham / List-WgvTypes.ps1
Last active May 10, 2016 02:05
List enum name and value from a .NET assembly
# running from same working directory as WatchGuard assemblies
#
$assembly = (Get-Item WatchGuard.Services.Contracts.dll).FullName
[system.reflection.assembly]::LoadFrom($assembly)
[Enum]::GetValues([WatchGuard.Services.AvduState]) | %{ Write-Host ( [int]$_):$_ }
# produces
# 0 :Unknown
@wgv-zbonham
wgv-zbonham / Dispose.cs
Last active November 6, 2015 11:40
IDisposable is a developer convention
public class Trash : IDisposable
{
public void Dispose()
{
Console.WriteLine ("Goodbye, cruel world.");
}
}
@wgv-zbonham
wgv-zbonham / GenerateCertificate.md
Last active April 26, 2016 22:40
Generating a private PFX certificate using openssl tools.

This configuration file does not ship with the version of openssl I pulled for some reason. Found a default openssl.cnf

  1. generate an RSA private key
  • openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
  1. write out the RSA private key
  • openssl rsa -passin pass:x -in server.pass.key -out server.key
  1. create the certificate signing request (CSR) for the server or common name;
  • openssl req -new -key server.key -out server.csr -config openssl.cnf -subj "/C=US/ST=TX/L=Allen/O=WatchGuard Video/CN=localhost"
  1. generate the x509 certificate from the request (this certificate will work in Root, but not WebHosting because no private key yet); this is normally handled by certificate CA
  • openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
@wgv-zbonham
wgv-zbonham / ShareLinksController.cs
Created June 23, 2015 23:04
Example of redirecting after taking some action (e.g. increment download count)
using System;
using System.Web.Http;
namespace WgvPlayback.Controllers
{
[RoutePrefix("/api/sharelinks")]
public class ShareLinksController : ApiController
{
public IHttpActionResult Get(Guid id)
{
@wgv-zbonham
wgv-zbonham / StorageContex.ps1
Created May 27, 2015 16:15
Storage Context for Non Default Azure Environments
<#
We only get Azure commercial and Azure China by default but this seems to work for Azure Gov by specifying the -Endpoint parameter
#>
$storageKey = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("My really long key that came from somewhere else and why isn't there a get-base64string cmdlet already??"))
$context = New-AzureStorageContext -StorageAccountName "Testing" -StorageAccountKey $storageKey -Endpoint "core.usgovcloudapp.net"
$context