Embed PowerShell code in a batch file

Embed PowerShell code in a batch file
Embed PowerShell code in a batch file

In a certain scenario, I needed a batch file (bat or cmd extension) that runs PowerShell code, and I could have only one file, so I couldn’t go with the easy way of a batch file calling PowerShell.exe with the -File parameter specifying the path to a ps1 file. For this, I created a special…

5

Passing down the WhatIf and Confirm preferences to other cmdlets from an Advanced Function

A colleague of mine was writing a cool function that tidies up the GPOs, and he wanted to implement the -WhatIf common cmdlet parameter in his function. There’s a simple way of doing that, just add the [cmdletBinding(SupportsShouldProcess)] and the param() blocks in the top of your function, add the if ($PSCmdlet.ShouldProcess($target)) {} in the…

1

Using VSCode and the PowerShell extension in an offline environment

The PowerShell ISE was first shipped with PowerShell 2.0 (November 2006), and greatly improved in PowerShell 3.0 (August 2012), with the PowerShell Tabs, the Show-Command Add-on and the snippets (CTRL+J). But since then, it pretty much stayed the same. Fast forward to May 2017, David Wilson from the PowerShell team announced (amongst other things) that:…

0