Skip to content

Instantly share code, notes, and snippets.

@fflaten
fflaten / Manifest.psd1
Last active August 9, 2022 17:01
Nested Module bug?
@{
ModuleVersion = '0.0.1'
GUID = 'e97ebdb4-5356-4d0d-9a6d-c851e91bf456'
NestedModules = @('Nested.psm1')
FunctionsToExport = 'publicFunc'
CmdletsToExport = '*'
VariablesToExport = '*'
AliasesToExport = '*'
}
@fflaten
fflaten / demo.ps1
Last active August 3, 2022 13:09
Pester ANSI-lookup demo
function Write-PesterHostMessage {
param(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[Alias('Message', 'Msg')]
$Object,
[System.ConsoleColor]
$ForegroundColor,
[System.ConsoleColor]
@fflaten
fflaten / PSSA.yml
Last active July 13, 2022 19:12
PSSA Scan integration in Github
# Will show entries in Code Security Alerts and as PR-comments
name: PSScriptAnalyzer Scan
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
@fflaten
fflaten / azure-pipelines.yml
Last active July 24, 2022 20:38
PSSA Scan integration in AzDO
# Install the SARIF Scan extension in Azure DevOps org. Will look for sarif-file in CodeAnalysisLogs artifact and show in Scans-tab
# https://marketplace.visualstudio.com/items?itemName=sariftools.scans
trigger:
branches:
include:
- main
paths:
exclude:
- .vscode/*
@fflaten
fflaten / regexdemo.js
Last active June 13, 2022 21:03
Javascript regex freeze
let reg = /(?:\$\{(?<specialName>.*?)(?<!`)\})|(?:\$(?:\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nd}|[_?])+:(?:\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nd}|[_?])+)|(?:\$(?:\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nd}|[_?])+)/giu
let str = " $pesterRuntimeInvocationContext = $PSCmdlet.SessionState.PSVariable.GetValue"
reg.exec(str)
// Changing the scoped group to \w, [a-zA-Z] etc. works fine), ex.
// let reg = /(?:\$\{(?<specialName>.*?)(?<!`)\})|(?:\$[a-zA-Z]+:(?:\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nd}|[_?])+)|(?:\$(?:\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nd}|[_?])+)/giu
@fflaten
fflaten / MockInModuleScope.tests.ps1
Created April 23, 2021 14:36
pester mock in module demo #1915
Describe 'Module-scoped mocks' {
BeforeAll {
$module = "demoModule"
$m = New-Module -Name $module -ScriptBlock {
function Invoke-SomeAction {
[CmdletBinding()]
param (
)