Skip to content

Instantly share code, notes, and snippets.


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
View azure automation sequence diagram

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
View Output.txt
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
View IsAttributeSetOrNot.ps1
$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 }
View 2015-NovemberScriptingGamesPuzzle.ps1
# 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
View VerifyTodaysLogExist.ps1
# 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
View CreateIFScheduledTasks.ps1
$TaskPath = ''
$TaskName = 'ImageFactory - Build {0} images'
csandfeld / 2015-OctoberScriptingGamesPuzzle.ps1
Last active October 4, 2015 21:35
@csandfeld 2015 - October Scripting Games Puzzle
View 2015-OctoberScriptingGamesPuzzle.ps1
function Get-RSSFeed {
Mandatory = $True
csandfeld / TrimCSV.ps1
Created September 26, 2015 12:08
Trim CSV data
View TrimCSV.ps1
# 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
View 2015-SeptemberScriptingGamesPuzzle.ps1
# 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
View 2015-AugustScriptingGamesPuzzle.ps1
# 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