Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
JustinGrote / IncorrectUseOfFormatCmdletsInMiddleOfPipeline.psm1
Last active September 6, 2022 11:33
Warn if Format command (Format-Table, etc.) are used in the middle of a pipeline.
using namespace System.Management.Automation.Language
using namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
function IncorrectUseOfFormatCmdletsInMiddleOfPipeline {
<#
.SYNOPSIS
Do not place format-table in the middle of a pipeline
.DESCRIPTION
Detects when Format commands are commonly misused in the middle of a pipeline, causing unexpected results with display objects that dont have the same properties as the original piped object.
@nohwnd
nohwnd / restore-environment.ps1
Created July 5, 2019 08:45
Automatically clean up changes in env variables after test
# this snippet describes how to automatically clean up
# changes in environment varables
# it can clean up re-writing, adding and removing
# scroll down to see how to use it in real test
Get-Module Pester | Remove-Module
Import-Module Pester -MaximumVersion 4.9.9
function Get-Environment {
$vars = Get-Item Env:\