Skip to content

Instantly share code, notes, and snippets.

@notesbytom
notesbytom / floating_point_issue.py
Last active July 13, 2016 01:26
Demonstrate Binary Floating Point Behavior with Decimal Fractions
# Note that standard binary computing floating point numbers cannot exactly represent simple decimal floating point numbers.
# This is the expected behavior for IEEE-754 compliant binary floating point processors
# https://en.wikipedia.org/wiki/IEEE_floating_point
# Case in point, 0.1 (1/10 = 10^-1) is between 1/8=2^-3 and 1/16=2^-4
# Since binary fraction cannot exacly store 1/10, accuracy of associated arithmetic is adversely impacted
# https://docs.python.org/3.5/tutorial/floatingpoint.html
# See the following example using Python 3.x
def test_binary_fraction():
mySum = 0
@notesbytom
notesbytom / TestArgs.ps1
Last active July 21, 2017 16:35
Mandatory Named Parameters for PowerShell Script File
# comment allowed before script param() statement
param([Parameter(Mandatory=$true)] $a, $b)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
"`$a = $a, `$b = $b"
$args
$MyInvocation
$PSBoundParameters
@notesbytom
notesbytom / Update-GAL.ps1
Created July 31, 2017 16:03
Synchronize CSV Contact List to Active Directory Global Address List
# NOTE: param() MUST BE FIRST STATEMENT in script file!!!
param([Parameter(Mandatory=$true)] $csvPath)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
Import-Module ActiveDirectory
# Get the CSV file path from an input parameter ($csvPath)
$people = Import-CSV $csvPath
# CONVERT EMPTY STRING FIELDS TO $null
@notesbytom
notesbytom / verify-tls.sh
Created October 25, 2017 15:23
Verify TLS SSL Certificate with OpenSSL
echo "Q" | openssl s_client -connect "your.fqdn.com:443" \
| openssl x509 -noout -text
@notesbytom
notesbytom / Get-Cert.ps1
Last active May 9, 2022 16:30
PowerShell View Remote Server Certificate Details
# This example lacks error checking
# late binding, call main AFTER defining check_ssl dependency
function main() { check_ssl -fqdn "your.fqdn.com" -port 443 }
function check_ssl($fqdn, $port) {
$tcpsocket = New-Object Net.Sockets.TcpClient($fqdn, $port)
$tcpstream = $tcpsocket.GetStream()
$sslStream = New-Object Net.Security.SslStream($tcpstream, $false)
$sslStream.AuthenticateAsClient($fqdn)
@notesbytom
notesbytom / clear-pfdb-on-mbxdb.ps1
Created November 14, 2017 22:15
Clear Old Public Folder Database Settings on Mailbox Databases in Exchange 2013+
import-module activedirectory
# Substitute correct values in place of * and com below.
cd "AD:\CN=Databases,CN=Exchange Administrative Group (*),CN=Administrative Groups,CN=*,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=*,DC=com"
get-item * -Properties msExchHomePublicMDB | `
foreach {
# Show name of mailbox database
$_.Name;
if ($_.msExchHomePublicMDB -eq $null) {
"NULL PF DB"
} else {
@notesbytom
notesbytom / certutil_view_issued_notexpired.bat
Last active November 29, 2017 16:14
Active Directory Certificate Services list certs that expire in future
REM Change the filter and column list as needed to match your query needs.
set filter="Disposition = 20,NotAfter > 11/29/2017"
set columns="NotAfter,CommonName,DistinguishedName,DispositionMessage,Disposition,CertificateTemplate,NotBefore,SerialNumber"
certutil -view -restrict %filter% -out %columns% >certutil_view_issued_notexpired.txt
REM see https://blogs.technet.microsoft.com/pki/2008/10/03/disposition-values-for-certutil-view-restrict-and-some-creative-samples/
@notesbytom
notesbytom / AdminSDHolderFix.ps1
Last active September 10, 2018 19:02
Fix AdminSDHolder SDProp Protected Users in Active Directory
$ErrorActionPreference = "Stop"
# Put usernames one-per-line in a text (CSV) file with header first-line: Username
# Set this to the path of your input csv file.
$CSVFilePath = "TroubleUsers.csv"
# This script will Clear the adminCount property and Enable Inheritance on the object Access Control List (ACL) in AD
$users = import-csv $CSVFilePath | sort Username
$groups = @()
foreach ($user in $users) {
@notesbytom
notesbytom / view_certs.ps1
Last active April 9, 2020 18:54
View Certificates for Server Name (ADCS certutil)
# Change the filter and column list as needed to match your query needs.
# Query Active Directory Certificate Services for Certs issued to given hostname
function view_certs($prefix, $config=$null) {
# call like: view_certs -prefix "srv-name"
# Find $config value by running "certutil" with NO OPTIONS
# increment last character to get next prefix (stop matching)
$nextprefix = $prefix.Remove($prefix.Length-1) + [char]([int]$prefix[-1] + 1)
@notesbytom
notesbytom / ChangeODBCDriver.vba
Last active October 3, 2018 19:04
Change ODBC Driver for Access Linked Tables
' Based on Stack Overflow Answer by @Fionnuala
' https://stackoverflow.com/questions/12606326/linked-table-ms-access-2010-change-connection-string
' NOTE: If a linked table is no longer valid, delete it and Restart Access or Compact the database
Function ChangeODBCDriver()
Dim tdf As TableDef
Dim oldDriver As String, newDriver As String
oldDriver = "SQL Server Native Client 10.0"
newDriver = "ODBC Driver 17 for SQL Server"
For Each tdf In CurrentDb.TableDefs
If tdf.Connect <> vbNullString Then