Skip to content

Instantly share code, notes, and snippets.

View bixb0012's full-sized avatar

Joshua Bixby bixb0012

View GitHub Profile
@bixb0012
bixb0012 / powershell_file_system_acls.ps1
Created March 2, 2025 16:03
PowerShell: File System ACLs
#Requires -Version 5.1
# Reference: 1) https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-acl?view=powershell-5.1
$DirectoryPath = "" # Path to directory, and subdirectories, to apply changes
$ExistingAccountName = "" # samAccountName or UserPrincipalName of account with existing
# file system object ACLs
$NewAccountName = "" # samAccountName or UserPrincipalName of account to assign
# file system object ACLs
# Example 1: Replace existing account access with same access for new account
@bixb0012
bixb0012 / arcpy_multi_value_to_single_value_attribute.py
Created February 2, 2025 20:22
ArcPy: Multi-value To Single-value Attribute
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/describe.htm
# 2) https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-feature-class.htm
# 3) https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-table.htmarc
# 4) https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/data-access-using-cursors.htm
# 5) https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/clear-workspace-cache.htm
import arcpy
from arcpy.management import CreateFeatureclass , CreateTable, ClearWorkspaceCache
@bixb0012
bixb0012 / powershell_esri.ps1
Last active July 24, 2024 15:40
PowerShell: Esri-related
#Requires -Version 5.1
# Reference: 1) https://github.com/Esri/cim-spec
# Reference: 2) https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=netframework-4.8.1
# Reference: 3) https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmlelement?view=netframework-4.8.1
# Reference: 4) https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-5.1
# Example 1: A function to convert Esri Cartographic Information Model (CIM) XML to a custom PSObject
# that has a property for each field in the XML content.
function ConvertFrom-EsriXml {
<#
@bixb0012
bixb0012 / powershell_console.ps1
Created April 7, 2023 15:11
PowerShell: Console-related
#Requires -Version 5.1
# Reference: 1) https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.runspace?view=powershellsdk-1.1.0
# Reference: 2) https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.powershell?view=powershellsdk-1.1.0
# Reference: 3) https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-progress?view=powershell-5.1
# Reference: 4) https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=netframework-4.8.1
# Example 1: Continuously watch Windows diagnostic counters in console progress bar
$Counters = @( # Windows diagnostic counter(s)
"\Processor(_total)\% Processor Time"
"\Memory\% Committed Bytes In Use"
@bixb0012
bixb0012 / powershell_conversion.ps1
Last active April 7, 2023 15:00
Powershell: Conversion-related
#Requires -Version 5.1
# Reference: 1) https://learn.microsoft.com/en-us/dotnet/api/system.web.script.serialization.javascriptserializer
# Example 1: Convert JSON text to native .NET data types
# Useful for PowerShell limited to .NET Framework classes
Add-Type -AssemblyName System.Web.Extensions
$Json = # JSON text
$Jss = [Web.Script.Serialization.JavaScriptSerializer]::New()
$Object = $Jss.DeserializeObject((Get-Content -Path $Json))
@bixb0012
bixb0012 / powershell_pki.ps1
Last active March 29, 2023 22:22
PowerShell: PKI-related
#Requires -Version 5.1
# Reference: 1) https://learn.microsoft.com/en-us/powershell/module/pki/new-selfsignedcertificate?view=windowsserver2019-ps
# Reference: 2) https://learn.microsoft.com/en-us/powershell/module/pki/export-certificate?view=windowsserver2019-ps
# Example 1: Create new self-signed certificate for use with Cryptographic Message Syntax (CMS) format
$NewCertArgs = @{
# KeyProtection = "Protect" # default is None
# KeyExportPolicy = "Exportable", "ExportableEncrypted" # default is "ExportableEncrypted"
KeyLength = 2048
KeyAlgorithm = "RSA"
@bixb0012
bixb0012 / powershell_measure_copy_performance.ps1
Last active March 2, 2025 15:25
PowerShell: Measure Copy Performance
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist
# Reference: 2) https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch
# Reference: 3) https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream
# Example 1: Copy file and measure combined (read & write) transfer rate over time
$FilePath = "" # Path of the file to copy
$Destination= "" # Path to the new directory or folder
$BufferSize = 64 # Buffer size, in KB, for copying file
@bixb0012
bixb0012 / python_class_tree_helpers.py
Created February 23, 2022 21:39
Python: Class Tree Helpers
#!python3
# Reference: 1) https://docs.python.org/3/library/stdtypes.html#special-attributes
# Example 1: Function to print base class or subclass hierarchies
def print_classtree(cls, bases=True, level=0):
print(f"{'-'*2*level} {cls}")
if bases:
classes = cls.__bases__
else:
classes = cls.__subclasses__()
@bixb0012
bixb0012 / powershell_security.ps1
Last active April 30, 2021 19:58
PowerShell: Security-related
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.security.principal
# Example 1: Retrieve security identifier value (SID) for an NT account
# Adapted from https://devblogs.microsoft.com/scripting/use-powershell-to-translate-a-users-sid-to-an-active-directory-account-name/
$DomainName = "" # Domain of account, commonly $Env:USERDOMAIN
$AccountName = "" # Name of account, commonly $Env:USERNAME
$NTAccount = [Security.Principal.NTAccount]::New($DomainName, $AccountName)
$Sid = ($NTAccount.Translate([Security.Principal.SecurityIdentifier])).Value
@bixb0012
bixb0012 / powershell_servicepointmanager_customizations.ps1
Last active April 26, 2021 21:56
PowerShell: ServicePointManager Customizations
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager
# Reference: 2) https://docs.microsoft.com/en-us/dotnet/api/system.net.security.remotecertificatevalidationcallback
# Example 1: Force TLS 1.2 connections from client
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Example 2: Ignore all SSL/TLS policy errors, e.g., ignore SSL/TLS secure channel errors
# from self-signed certificates