Skip to content

Instantly share code, notes, and snippets.

@kspeeckaert
kspeeckaert / Delegated_Queries.ps1
Created April 19, 2022 15:10
Retrieve Denodo Delegated Queries
[cmdletbinding()]
param (
[Parameter(Mandatory=$true)] [string] $WhereClause,
[Parameter(Mandatory=$true)] [string] $ExportFilename,
[switch] $ForceExport
)
# Load ODBC utility functions
. $PSScriptRoot\odbc_utils.ps1
@kspeeckaert
kspeeckaert / odbc_utils.ps1
Created April 14, 2022 13:29
ODBC utility functions in PowerShell
function Get-CredsConnString() {
[OutputType([hashtable])]
[cmdletbinding()]
param (
[Parameter(Mandatory=$true)][PSCredential] $Credential
)
$PlainCred = [ordered] @{
UID = $Credential.UserName
PWD = [PSCredential]::new(0, $Credential.Password).GetNetworkCredential().Password
}
@kspeeckaert
kspeeckaert / RemoteCopy.ps1
Created April 14, 2022 10:53
Remote Copy
[cmdletbinding()]
param (
[Parameter(Mandatory)][System.IO.DirectoryInfo]$SourceFolder,
[Parameter(Mandatory)][string]$RemoteFolder,
[Parameter(Mandatory)][string]$Server,
[Parameter(Mandatory)][pscredential]$Credential
)
function New-TemporaryDirectory {
@kspeeckaert
kspeeckaert / Send-CustomMail.psm1
Created November 15, 2021 15:17
Send-MailMessage wrapper, with additional functionality to send attachments as an archive
function Send-CustomMail {
[cmdletbinding()]
param (
[Parameter(Mandatory)][string[]]$To,
[Parameter(Mandatory)][string]$Subject,
[Parameter(Mandatory)][string]$Body,
[string]$SMTPServer = 'SMTP.ACME.LOCAL',
[string]$From = 'support@acme.local',
@kspeeckaert
kspeeckaert / Mount-Share.ps1
Created October 12, 2021 07:45
Mount a remote share (to be used with RoyalTS)
#Requires -Module BurntToast
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)] [String]$ComputerName,
[Parameter(Mandatory=$true)] [String]$Username,
[Parameter(Mandatory=$true)] [String]$Password
)
function Get-DisplayName {
@kspeeckaert
kspeeckaert / Test-DCResponse.ps1
Last active September 16, 2021 10:21
Given a username and a domain, perform a lookup on each DC and measure the time it takes (if successful).
function Test-ADUser() {
[CmdletBinding()]
<#
Perform a user account lookup on a given DC and return a boolean
indicating success or failure.
#>
param(
[string]$UserName,
[string]$Server
)
@kspeeckaert
kspeeckaert / Set-OOO.ps1
Last active September 20, 2021 08:02
Activate out of office using PowerShell
#Requires -Module ExchangeOnlineManagement
#Requires -Module BurntToast
$UPN = 'john.appleseed@apple.com'
$DateFormatCulture = [CultureInfo]'en-GB'
# This has to be at the top, before the calendar, to avoid the 'single thread apartment' error
Write-Host 'Connecting to Exchange Online...'
Connect-ExchangeOnline -UserPrincipalName $UPN
@kspeeckaert
kspeeckaert / WaitForIt.ps1
Last active September 13, 2021 11:47
Wait until a remote host comes online and has RDP available, after a reboot.
#Requires -Module BurntToast
[cmdletbinding()]
param (
[Parameter(Mandatory)][string]$ComputerName,
[Parameter(Mandatory)][string]$ConnectionID
)
function Test-TCPPort {
# Replacement for Test-NetConnection, because ping cannot be disabled.
@kspeeckaert
kspeeckaert / pdf_toc_to_opml.py
Last active September 16, 2019 11:07
Extract the table of contents from a PDF file and save it as an OPML, e.g. for import into a mind map
# Requirements
# yattag==1.12.2
# PyPDF2==1.26.0
# Tested with Python 3.7.4 on macOS
import sys
from pathlib import Path
@kspeeckaert
kspeeckaert / Answer
Created July 24, 2016 22:18
SO: Pandas gives an error from str.extractall('#')
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{