Skip to content

Instantly share code, notes, and snippets.

View powercode's full-sized avatar

Staffan Gustafsson powercode

  • DICE
  • Stockholm, Sweden
  • 11:53 (UTC +02:00)
View GitHub Profile
@powercode
powercode / ArgumentCompleterBase.cs
Last active February 25, 2018 14:22
CompleterBase : base class for PowerShell argument completers
/// <summary>
/// Base class for writing custom Argument Completers
/// </summary>
/// <para>Derived classes should override <see cref="AddCompletionsFor(string,string,IDictionary)"/> </para>
public abstract class ArgumentCompleterBase : IArgumentCompleter
{
private List<CompletionResult> _results;
/// <summary>
using namespace System.Management.Automation
using namespace System.Collections.Generic
class ArgumentCompleterBase : IArgumentCompleter {
hidden [List[CompletionResult]] $Results = [List[CompletionResult]]::new()
[string] $WordToComplete
[Language.CommandAst] $commandAst
# override in child class
[void] AddCompletionsFor([string] $commandName, [string] $parameterName, [Collections.IDictionary] $fakeBoundParameters) {}
@powercode
powercode / Set-PowerPointLanguage.ps1
Last active April 9, 2018 06:23
Set-PowerPointLanguage
<#
.SYNOPSIS
Change language settings for a PowerPoint presentation
.EXAMPLE
PS> Set-PowerPointLanguage -Path MyPres.pptx
Writes a copy of MyPres.pptx to MyPres.en-us.pptx with the language set to 'en-US' - English (the default)
.EXAMPLE
PS> Set-PowerPointLanguage -Path MyPres.pptx -Language de-DE
@powercode
powercode / Send-PSNotification.ps1
Created January 25, 2019 15:40
Send-PSNotification
<#
.SYNOPSIS
Sends a notification on Linux.
.DESCRIPTION
Sends a notification on Linux. Under the hood, this uses notify-send(1)
.PARAMETER Body
The body or main content of the notification.
@powercode
powercode / Send-PSNotification.ps1
Last active January 28, 2019 12:53
Send-PSNotification
<#
.SYNOPSIS
Sends a notification on Linux.
.DESCRIPTION
Sends a notification on Linux. Under the hood, this uses notify-send(1)
.PARAMETER Body
The body or main content of the notification.
@powercode
powercode / ImportCsvWithType.ps1
Last active March 11, 2025 10:27
Automatic generation of a class to store data from import-csv
function New-TypeDefinitionFromCsv {
param(
[Parameter(Mandatory)]
[string] $Path,
[ValidatePattern("\w[\w\d_-]*", ErrorMessage = "The typename must be a valid name of an Identifier.")]
[string] $NameOfGeneratedType,
[ArgumentCompletions('";"', '"`t"', '","')]
[string] $Delimiter = ',',
[Type[]] $ColumnType,
[switch] $CSharp