Skip to content

Instantly share code, notes, and snippets.

View csandfeld's full-sized avatar

Christian Sandfeld csandfeld

  • Demant A/S
  • Copenhagen
View GitHub Profile
csandfeld / azure automation sequence diagram
Last active July 22, 2022 14:03
azure automation sequence diagrams

sequenceDiagram autonumber

actor User as Requester
participant AYS as At Your Service
participant SM as Service Manager
participant Init as Init Script
participant Transaction as Transaction Runbook
participant Action as Action Runbook(s)

participant Share as File Share

csandfeld / Output.txt
Created January 9, 2019 16:51
Testing Custom Validators and Transforms
VERBOSE: Loading module from path 'C:\Custom Validators and Transforms\TestMod.psm1'.
VERBOSE: Exporting function 'Test-OwnClass'.
VERBOSE: Exporting function 'Test-ValidatePathExists'.
VERBOSE: Exporting function 'Test-PathTransform'.
VERBOSE: Importing function 'Test-OwnClass'.
VERBOSE: Importing function 'Test-PathTransform'.
VERBOSE: Importing function 'Test-ValidatePathExists'.
csandfeld / IsAttributeSetOrNot.ps1
Last active May 2, 2016 10:52
Working with file attributes
$Path = 'C:\TEMP\TEST1'
$Filter = '*.pdf'
$Attribute = [System.IO.FileAttributes]::Archive
# Get all files in $Path matching $Filter
Get-ChildItem -Path $Path -Filter $Filter -Recurse
# Get all files in $Path matching $Filter where $Attribute is set
Get-ChildItem -Path $Path -Filter $Filter -Recurse | Where-Object { $_.Attributes -band $Attribute }
# Split string by comma, and trim of any whitespace
csandfeld / VerifyTodaysLogExist.ps1
Last active November 3, 2015 19:37
Script to check if log file created today exist
# Folder where logfiles are stored
$Path = 'C:\TEMP'
# Filename pattern for regex match operator (<guid>.log)
$Pattern = '^.{8}-.{4}-.{4}-.{4}-.{12}\.log$'
$From = ''
$To = ''
$SmtpServer = 'smtpserver.domain.local'
$Subject = 'Todays log file was not found'
csandfeld / CreateIFScheduledTasks.ps1
Last active October 30, 2015 10:42
Image Factory: Create Scheduled Tasks
$TaskPath = ''
$TaskName = 'ImageFactory - Build {0} images'
csandfeld / 2015-OctoberScriptingGamesPuzzle.ps1
Last active October 4, 2015 21:35
@csandfeld 2015 - October Scripting Games Puzzle
function Get-RSSFeed {
Mandatory = $True
csandfeld / TrimCSV.ps1
Created September 26, 2015 12:08
Trim CSV data
# Specify input and output files
$InputCSVFile = '.\input.csv'
$OutputCSVFile = '.\output.csv'
# Import data from CSV
$CSVData = Import-Csv -Path $InputCSVFile
# Run trim() (remove leading and trailing whitespace) on all property values
$CSVTrimmedData = $CSVData | Foreach-Object {
csandfeld / 2015-SeptemberScriptingGamesPuzzle.ps1
Last active September 6, 2015 15:14
@csandfeld 2015 - September Scripting Games Puzzle
# No semicolons, only one set of curlies, using aliases etc. to keep it as short as possible
ipcsv I*|%{$_|Add-Member OSVERSION (gwmi -CN $_.MACHINENAME Win32_OperatingSystem).Caption -P}|epcsv Output.csv
# Same as the above, but longer as I am not taking shortcuts with aliases and an incomplete filename
Import-Csv Input.csv | %{ $_ | Add-Member OSVERSION (Get-WmiObject -ComputerName $_.MACHINENAME Win32_OperatingSystem).Caption -PassThru } | Export-Csv Output.csv
# How I would have done it, had there been no limitations on lenght, semicolons
# One-liner, command and parameter names spelled out
Invoke-RestMethod -Uri '' | Format-Table -Property longitude, latitude, continent_code, timezone
# Advanced function wrapping the JSON endpoint
function Get-GeoInformation {
Get IP address geo information