Skip to content

Instantly share code, notes, and snippets.

View ctigeek's full-sized avatar

Steven Swenson ctigeek

View GitHub Profile
@ctigeek
ctigeek / PowershellAes.ps1
Last active March 25, 2024 23:16
Aes Encryption using powershell.
function Create-AesManagedObject($key, $IV) {
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
$aesManaged.BlockSize = 128
$aesManaged.KeySize = 256
if ($IV) {
if ($IV.getType().Name -eq "String") {
$aesManaged.IV = [System.Convert]::FromBase64String($IV)
}
@ctigeek
ctigeek / Remove-Service.ps1
Last active November 8, 2017 15:28
Delete a windows service.
function Remove-Service {
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)] [object] $service
)
BEGIN { }
PROCESS {
$serviceName = $service.Name
if (-not $serviceName) {
@ctigeek
ctigeek / Install-Chocolatey.ps1
Created August 27, 2015 14:50
Install chocolatey and other stuff...
Invoke-WebRequest https://chocolatey.org/install.ps1 -OutFile C:\Windows\Temp\chocoInstall.ps1
. C:\Windows\Temp\chocoInstall.ps1
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
choco install -y 7zip
choco install -y notepadplusplus
choco install -y google-chrome-x64
##choco install -y nodejs ##broken
choco install -y visualstudiocode
@ctigeek
ctigeek / server.js
Created August 27, 2015 17:27
Host nodejs website under IIS with domain authentication.
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("blah blah\n\n");
response.write(JSON.stringify(request.headers,null,' '));
response.write("\n\n" + request.method);
response.write(request.url);
response.end("\n\nHello World\n");
});
@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
}
@ctigeek
ctigeek / SendMailgunEmail.ps1
Last active January 2, 2023 17:36
Send an email using Mailgun in Powershell.
function Send-MailgunEmail($from, $to, $subject, $body, $emaildomain, $apikey) {
$idpass = "api:$($apikey)"
$basicauth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($idpass))
$headers = @{
Authorization = "Basic $basicauth"
}
$url = "https://api.mailgun.net/v2/$($emaildomain)/messages"
$body = @{
from = $from;
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
@ctigeek
ctigeek / LogoutAllUsers.ps1
Created November 2, 2015 14:03
Logout every user on a machine with extreme prejudice.
function Logout-AllUsers($computerName) {
(gwmi win32_operatingsystem -ComputerName $computerName).Win32Shutdown(4)
}