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 / 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 / ListODBCDrivers.ps1
Created October 3, 2018 17:22
List ODBC Drivers on Windows 7 / Server 2008 with PowerShell
# List Native Architecture Drivers Installed (64-bit if Windows is x64)
Get-Item 'HKLM:\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers'
# List 32-Bit Drivers Installed on 64-bit Windows (not applicable to 32-bit Windows)
Get-Item 'HKLM:\software\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers'
# Alternatively use Get-ItemProperty
# Windows 8, Server 2012 and newer have Get-OdbcDriver cmdlet available (easier to use)
@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
@notesbytom
notesbytom / Show-SpecialPaths.ps1
Created March 26, 2019 17:31
Show Special Folder Paths (Windows)
# Show Special Folder Paths (Windows PowerShell)
function Show-SpecialPaths () {
foreach ($fName in [System.Enum]::GetNames([System.Environment+SpecialFolder])) {
New-Object PSObject -Prop ([ordered]@{ 'Name'=$fName; 'Value'=[System.Environment]::GetFolderPath($fName) })
}
}
# Shows if desktop, documents, etc are redirected.
Show-SpecialPaths