Skip to content

Instantly share code, notes, and snippets.

@msm-fc
msm-fc / AD group enumeration with LDAP in PowerShell Core.ps1
Last active January 3, 2023 11:06
Demonstrates AD group enumeration with LDAP in PowerShell Core. Uses the Novell.Directory.LDAP.VQ DotNet Standard 2.0 library
#Demonstrates listing an Active Directory group membership with PowerShell Core
using namespace Novell.Directory.LDAP.VQ
#region environment-specific config
$DCname = 'DomainControllerName'
# Don't store user credentials in your powerShell scripts!!
# This is just here to demonstrate POC.
$ldapUser = 'CN=powershell-ldap,CN=Users,DC=Corporate,DC=Contoso,DC=com'
@msm-fc
msm-fc / Get-HelpscoutToken.ps1
Last active September 24, 2019 16:06
Fetches a cached bearer token for Helpscout authentication 2.0, refreshing it if necessary
Function Get-HelpscoutToken
{
#Fetches a cached bearer token for Helpscout authentication 2.0, refreshing it if necessary
#returns the token as plaintext for easy integration into invoke-restmethod
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$helpscout_token_path,
@msm-fc
msm-fc / remove_xml_nodes.ps1
Created November 2, 2018 17:36
Remove all XML child nodes of the same name from a single parent node with PowerShell
#Remove all XML child nodes of the same name from a single parent node
#this works in PowerShell version 5.1 (older versions are not tested)
[xml]$xml = @"
<system.webServer>
<httpProtocol>
<customHeaders>
<!--Override the IE broweser's Compatibility View Settings for intranet sites.-->
<add name="X-UA-Compatible" value="IE=Edge" />
@msm-fc
msm-fc / modify_custom_view.ps1
Created November 2, 2018 00:20
Inject new query into existing Event Viewer Custom View
#region config
$customViewFile = "path to custom view XML file"
$newCustomViewFile = "path to updated custom view XML file"
$newQuery = "*[System[Provider[@Name='Microsoft-Windows-WAS'] and (Level=3) and (EventID=5210)]]"
#endregion
#region operations
[xml]$customView = gc $customViewFile
$customview.SelectSingleNode("//Query").InnerText = $newQuery
$customView.Save($newCustomViewFile)
@msm-fc
msm-fc / Sieve of Eratosthenes.ps1
Last active July 25, 2018 20:24
Sieve of Eratosthenes
<#
Sieve of Eratosthenes in PowerShell
converted from C++ and Java code found here:
http://www.algolist.net/Algorithms/Number_theoretic/Sieve_of_Eratosthenes
2018 Matt Musante
Public Domain
#>
function runEratosthenesSieve{param ([int]$upperBound)
[int]$upperBoundSquareRoot = [Math]::Floor([math]::Sqrt($upperBound))