Skip to content

Instantly share code, notes, and snippets.

View indented-automation's full-sized avatar

Chris Dent indented-automation

View GitHub Profile
function Measure-ChildItem {
<#
.SYNOPSIS
Recursively measures the size of a directory.
.DESCRIPTION
Recursively measures the size of a directory.
Measure-ChildItem uses win32 functions, returning a minimal amount of information to gain speed. Once started, the operation cannot be interrupted by using Control and C. The more items present in a directory structure the longer this command will take.
This command supports paths longer than 260 characters.
@indented-automation
indented-automation / Enable-ScriptAlias.ps1
Last active February 29, 2024 07:50
A bit of fun, replaces full command names with aliases
using namespace System.Management.Automation.Language
function Enable-ScriptAlias {
<#
.SYNOPSIS
Replace all aliased commands in a script with the alias name.
.DESCRIPTION
Replace all aliased commands in a script with the alias name.
@indented-automation
indented-automation / ActiveDirectory.md
Last active February 7, 2024 16:59
Active Directory

A small collection specialised scripts for Active Directory.

Includes:

  • Compare-ADMemberOf
  • Get-ADSystemInfo
  • Get-GroupMemberTree
  • Get-LdapObject
  • Get-MemberOfTree
  • Test-LdapSslConnection
using module ActiveDirectory
using namespace System.Reflection
function Convert-ADFilter {
<#
.SYNOPSIS
Converts PowerShell-style filters used by the AD module into LDAP filters.
.DESCRIPTION
Convert-ADFilter uses the QueryParser from the AD module to convert PowerShell-style filters into LDAP
@indented-automation
indented-automation / Get-LdapAcl.ps1
Last active January 4, 2024 16:15
Get LDAP ACL
using assembly System.DirectoryServices.Protocols
using namespace System.DirectoryServices.Protocols; using namespace System.Collections.Generic
function Get-LdapObject {
<#
.SYNOPSIS
Get objects from an LDAP directory.
.DESCRIPTION
Get objects from an LDAP directory.
.EXAMPLE
using namespace System.Collections.Generic; using namespace System.Text
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
using System.Text;
public class WindowTools
{
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
function ConvertTo-TableFormat {
<#
.SYNOPSIS
Rebuild an object based on the Format Data for the object.
.DESCRIPTION
Allows an object to be rebuilt based on the view data for the object. Uses Select-Object to create a new PSCustomObject.
#>
[CmdletBinding()]
param (
@indented-automation
indented-automation / bam.ps1
Created September 5, 2023 12:02
Background Activity Moderator
Add-Type -TypeDefinition @'
using System.Runtime.InteropServices;
using System.Text;
public class Native
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint QueryDosDevice(
string lpDeviceName,
StringBuilder lpTargetPath,
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Reflection
function Get-FunctionInfo {
<#
.SYNOPSIS
Get an instance of FunctionInfo.
.DESCRIPTION
FunctionInfo does not present a public constructor. This function calls an internal / private constructor on FunctionInfo to create a description of a function from a script block or file containing one or more functions.
function Update-RegistryFile {
<#
.SYNOPSIS
Updates a registry file.
.DESCRIPTION
Line break and certain characters will not import from standard registry files (even if export works).
This function replaces any entry with line breaks with a hex value representing the string.
#>