Skip to content

Instantly share code, notes, and snippets.

@LaurentDardenne
LaurentDardenne / Test-ModuleNaming.ps1
Created September 12, 2023 14:26
Tests, only after a call of Save-Module, the case of the file names of a published module (.nupkg).
function Test-ModuleNaming {
#We test the naming of a module.
#see : https://github.com/PowerShell/PowerShell/issues/17342
# https://github.com/Splaxi/PSNotification/issues/15
param(
#Name of module directory to check.The name come from the nuget package ( case sensitive)
$ModuleName,
$Version,
@LaurentDardenne
LaurentDardenne / RedirectStdout
Created January 7, 2023 13:55
Set the console output (stdout) to a stream
#from https://github.com/PowerShell/PowerShell/issues/18364#issuecomment-1289401093
$Writer = [System.IO.StreamWriter]::new("$HOME\DemoLog.txt")
$Writer.AutoFlush = $true
$OriginalOut = [System.Console]::Out
try
{
[System.Console]::SetOut($Writer)
[System.Console]::WriteLine("Hello")
}
@LaurentDardenne
LaurentDardenne / Get-VariableType
Created October 14, 2022 14:46
Get-VariableType : Workaround to get the type of PSVariable when it s $null
function Get-VariableType {
#If a PSVariable is $null, it is impossible to get his type.
#One must read the _convertTypes member of ArgumentTypeConverterAttribute class.
#Origin : http://poshcode.com/998
param([string]$Name)
Write-Debug ("Call : {0}" -F $MyInvocation.InvocationName)
get-variable $name | select -expand attributes | ? {
$_.gettype().name -eq "ArgumentTypeConverterAttribute" } | % {
$_.gettype().invokemember("_convertTypes", "NonPublic,Instance,GetField", $null, $_, @())
}
@LaurentDardenne
LaurentDardenne / Actionlint.ps1
Created September 7, 2022 11:13
Invokebuild : task Actionlint
task Actionlint {
# Linting all workflow files only in .\.github\workflows directory
if (Get-Command gh.exe)
{
$isActionLintExist=(gh extension list|Where-Object {$_ -match 'actionlint'}|Select-Object -first 1) -ne $null
if (-not $isActionLintExist)
{ Throw "Github Cli: 'actionlint' extension not found. Use : gh extension install cschleiden/gh-actionlint"}
$ActionLintErrors=gh actionlint -format '{{json .}}'|ConvertFrom-Json