Skip to content

Instantly share code, notes, and snippets.

@sean-m
sean-m / epoch.vbs
Last active April 3, 2019 08:09
vbscript function for calculating Unix epoch, the universal machine readable timestamp.
Function UnixEpoch
Dim utc_now, t_diff, objWMIService, colItems, item
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
'Get UTC time string
Set colItems = objWMIService.ExecQuery("Select * from Win32_UTCTime")
For Each item In colItems
If Not IsNull(item) Then
@sean-m
sean-m / GetSizeRecurse.ps1
Last active October 12, 2016 18:57
Enumerates files in a directory getting both the regular and compressed size. The enumeration happens in a pipeline function so it's memory efficient. The input parameter $Path is checked for type so if you pipe the output of Get-ChildItem into the function it will use the FullName parameter as the path.
<#
.Synopsis
Gets directory sizes quickly.
.DESCRIPTION
Enumerates files in a directory getting both the regular
and compressed size. The enumeration happens in a pipeline
function so it's memory efficient. The input parameter $Path
is checked for type so if you pipe the output of Get-ChildItem
into the function it will use the FullName parameter as the path.
@sean-m
sean-m / NativeFSEnumeration.cs
Last active September 9, 2016 22:57
1 file library that wraps FindFirstFileEx and FindNextFile Win32 functions to quickly enumerate the filesystem. This is an alternative to System.IO.File.GetFile and GetDirectory, this is mainly a toy exercise in performance. If you are trying to avoid exceptions in Directory.GetFiles, Marc Gravel has a great solution here: http://stackoverflow.c…
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace NativeHelpers
{
public static class NativeHelpers
{
//
@sean-m
sean-m / psdedupe.ps1
Created April 11, 2016 19:38
Non optimal, quick hack when sort -unique and select -unique didn't do what I want.
function Dedupe {
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelinebyPropertyName=$false,
Position=0)]
$obj,
[Parameter(Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelinebyPropertyName=$false,
@sean-m
sean-m / Posh_Dashboard.ps1
Last active October 17, 2022 14:45
Simple WPF dashboard script with functions mapped to buttons. Uses command pattern to map button clicks to PowerShell script blocks.
<#
Simple WPF dashboard script with functions mapped to buttons.
Uses command pattern to map button clicks to PowerShell script
blocks.
How it kinda works:
The WPF UI for PowerShell idea I got from here:
https://foxdeploy.com/2015/04/16/part-ii-deploying-powershell-guis-in-minutes-using-visual-studio/
@sean-m
sean-m / Check_Group_Managers.ps1
Created September 9, 2016 23:01
Allows you to set a list of groups and will enumerate the properties which set managers as well as the group's ACL, telling you who can manage group members.
<#
This script will show who is listed as a group manager and who has
rights to modify the group members. Just populate the $groupNames
list with group names, wildcards are allowed.
#>
$groupNames = @(
"Some Group Name"
)
@sean-m
sean-m / PshGzip.psm1
Last active September 19, 2023 15:27
PowerShell module with functions to assist reading and writting GZip compressed files.
#Requires -Version 4
#Load Types
{
if (-not ([System.Management.Automation.PSTypeName]'CompressHelper').Type) {
Add-Type -Language CSharp -TypeDefinition @"
using System;
using System.IO;
using System.Threading.Tasks;
public static class CompressHelper {
@sean-m
sean-m / ZenburnISE.StorableColorTheme.ps1xml
Last active November 11, 2022 15:24
Zenburn theme for PowerShell ISE
<?xml version="1.0" encoding="utf-16"?>
<StorableColorTheme xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Keys>
<string>ErrorForegroundColor</string>
<string>ErrorBackgroundColor</string>
<string>WarningForegroundColor</string>
<string>WarningBackgroundColor</string>
<string>VerboseForegroundColor</string>
<string>VerboseBackgroundColor</string>
<string>DebugForegroundColor</string>
@sean-m
sean-m / transform-ldif.ps1
Last active September 30, 2017 04:50
Script that does string replacement on LDIF files. Not optimal for that exact purpose as it converts them to powershell objects first but if you ever need to parse an LDIF file into PowerShell objects here's a script to do that.
#Requires -Version 3
# Transforms objects from LDIF formatted file, parses file into PowerShell
# objects, then does string replace operations on all properties.
# Good Luck
# Works starts around line 170
####################################################################
## Functions ##
####################################################################
@sean-m
sean-m / Make-UniquePath.ps1
Created February 2, 2017 21:05
Increments a number in a file path until the path is unique. Got tired of writing this every time I need it.
function Make-UniquePath {
param([string]$path)
$ptemp = $path
$inc = 1;
$ext = [IO.Path]::GetExtension($path)
while (Test-Path $ptemp) {
$tmp_ext = [String]::Concat("-",$inc.ToString("D2"),$ext)
if ([String]::IsNullOrEmpty($ext)) {
$ptemp = [String]::Concat($path,$tmp_ext)