Skip to content

Instantly share code, notes, and snippets.

View ctigeek's full-sized avatar

Steven Swenson ctigeek

View GitHub Profile
@ctigeek
ctigeek / CreateDomainForest.ps1
Created January 27, 2015 19:45
Create Domain Forest
Install-WindowsFeature -Name Ad-Domain-Services -IncludeManagementTools
###local admin password....
$pass = ConvertTo-SecureString "XXXXXXXXXX" -AsPlainText -Force
Install-ADDSForest -DomainName "MyNewDomain.local" -SafeModeAdministratorPassword $pass
@ctigeek
ctigeek / scheduling.cs
Last active August 29, 2015 14:16
Sudo code for scheduling
//The idea here is there's a difference between how the event repeats (Repetition) and when that repetition occurs (When/NotWhen).
// Between 9am and 6pm, run every 5 minutes, exactly on minute 0,5,10,etc., except on the last day of the month.
// Before 9am and after 6pm, run every 10 minutes, exactly on minute 0,10,20, etc, except on the last day of the month.
// On the last day of the month, run every 20 minutes, exactly on minute 0,20,40.
var config = ScheduleConfig.EveryMinute(5).OnTheMinute(0).When(Between(Hour(9),Hour(18))).WhenNot(DayOfMonth.Last).Named("DayTime")
.AddRepetition(Repetition.EveryMinute(10).OnTheMinute(0).When(Before(Hour(9)), After(Hour(18))).WhenNot(DayOfMonth.Last).Named("NightTime")
.AddRepetition(Repetition.EveryMinute(20).OnTheMinute(0).When(DayOfMonth.Last).Named("LastDayOfMonth");
var schedule = new Schedule(scheduleConfig); //This could also be IObservable....
@ctigeek
ctigeek / fileserver.js
Created March 18, 2015 13:18
Simple static file server
var http = require('http');
var url = require("url");
var path = require("path");
var fs = require('fs');
http.createServer(function(req, res) {
var uri = url.parse(req.url).pathname;
var filename = path.join(process.cwd(), uri);
if (fs.existsSync(filename)) {
var stats = fs.lstatSync(filename);
@ctigeek
ctigeek / EncryptString.cs
Created April 3, 2015 00:39
Encrypt String
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace SandboxThing
{
class EncryptedString
{
private const int AesBlockSize = 128;
@ctigeek
ctigeek / StaticIP.ps1
Created April 7, 2015 16:27
Change server from DHCP to static...
$adapter = Get-NetAdapter -Name "Ethernet"
$ipv4 = $adapter | Get-NetIPAddress -AddressFamily IPv4
## Remove IPv6 Address and disable IPv6 binding....
$ipv6 = $adapter | Get-NetIPAddress -AddressFamily IPv6 -ErrorAction SilentlyContinue
if ($ipv6) {
$ipv6 | Remove-NetIPAddress -Confirm:$false
}
$binding = (Get-NetAdapterBinding | Where-Object { $_.ComponentID -eq "ms_tcpip6" })
@ctigeek
ctigeek / Clear-Memcache.ps1
Created May 14, 2015 20:01
Flush memcache from powershell...
function Clear-Memcache($server, $port = 11211)
{
$msg = [System.Text.Encoding]::ASCII.GetBytes("flush_all`r`nquit`r`n")
$c = New-Object System.Net.Sockets.TcpClient($server, $port)
$str = $c.GetStream()
$str.Write($msg, 0, $msg.Length)
$buf = New-Object System.Byte[] 4096
$count = $str.Read($buf, 0, 4096)
[System.Text.Encoding]::ASCII.GetString($buf, 0, $count)
$str.Close()
@ctigeek
ctigeek / MockActionCallback.cs
Created September 8, 2015 21:53
Mocking a method that takes an action which Sets a Threading.ManualResetEvent
//code from NServicebus....
public static int WaitForReturn(this ICallback callback, TimeSpan timeout)
{
int returnValue = 0;
ManualResetEvent handle = new ManualResetEvent(false);
callback.Register((Action<int>) (i =>
{
returnValue = i;
handle.Set();
}));
@ctigeek
ctigeek / TortoiseDiffAllFiles.ps1
Created September 28, 2015 17:46
Compare all the files of the same name in two directories.
Get-ChildItem C:\dir\* | %{
$file1 = "C:\dir\$($_.Name)"
$file2 = "C:\dir\$($_.Name)"
. 'C:\Program Files\TortoiseGit\bin\TortoiseGitMerge.exe' -mine $file1 -base $file2
#it takes a few seconds to open gitmerge. If you don't include this sleep your computer will implode.
Start-Sleep -Seconds 5
}
@ctigeek
ctigeek / Create-AspSessionDatabase.ps1
Last active October 9, 2015 15:51
Create ASP Temp session tables & stored procs.
function Create-AspSessionDatabase ($dataSource, $database) {
. C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe -S $dataSource -d $database -ssadd -E -sstype c
}
function Copy-WUPowershellModule($computerName) {
$remotePath = "\\$($computerName)\c$\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate"
$localPath = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate"
if (! (Test-Path $remotePath )) {
Write-Host "Copying powershell module."
Copy-Item $localPath -Destination $remotePath -Recurse -Force
}
$command = {
##Add the Microsoft Update service
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false