Skip to content

Instantly share code, notes, and snippets.

@gerane
gerane / Fails.ps1
Created July 1, 2016 17:18
Just adding <# #> allows Get-Help to see the parameter attribute help. Removing <# #> breaks Help even if the parameter attributes are present.
function Test-WildCardsWorks
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,
Position=0,
ParameterSetName="Path",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
# Is there a reason why one might use Example 1 over Example 2 if only using a single command?
## Example 1
New-Module -Name SomeModule -Function "SomeFunction" -ScriptBlock { Function SomeFunction { Write-Host "Invoking SomeFunction with $params"} } | Import-Module
## Example 2
Function SomeFunction { Write-Host "Invoking SomeFunction with $params"}
## Example Usage
Describe "Invoke-Something" {
Register-EditorCommand `
-Name "MyModule.OpenPowerShellConsole" `
-DisplayName "Open PowerShell Console" `
-SuppressOutput `
-ScriptBlock {
$Arch = (Get-WmiObject -Class 'Win32_Processor').AddressWidth
If ($Arch -eq '64')
{
#launch powershell via sysantive here
@gerane
gerane / Faking_Static_Call_in_Pester.ps1
Created May 25, 2016 00:51 — forked from nohwnd/Faking_Static_Call_in_Pester.ps1
Faking call to external static method in Pester
add-type -TypeDefinition @"
using System;
public static class KeyboardEventTestUtil {
public static string keybd_event(byte bVk, byte bScan, UInt32 dwFlags, System.UIntPtr dwExtraInfo) {
return string.Format("{0}:{1}:{2}:{3}", bVk,bScan,dwFlags,dwExtraInfo);
}
}
"@
describe "t" {
@gerane
gerane / TestingStartService.ps1
Created May 25, 2016 00:50 — forked from nohwnd/TestingStartService.ps1
Testing start service
function EnsureServiceStarted {
param($Name)
Start-Service -name $name
$service = Get-Service -Name $name
$service.Status -eq [ServiceProcess.ServiceControllerStatus]::Running
}
Describe "Ensure service is started" {
It "Started service returns true" {
mock start-service {}
Register-EditorCommand `
-Name "Helpers.EditVSCodeProfile" `
-DisplayName "Edit VS Code Profile" `
-SuppressOutput `
-ScriptBlock {
param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context)
$psEditor.Workspace.OpenFile("$env:USERPROFILE\OneDrive\PowerShell\Profiles\Microsoft.VSCode_profile.ps1")
}
Register-EditorCommand `
Import-Module Emojis
function Invoke-EmojiSelection
{
[Cmdletbinding()]
param
(
[Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context
)
$EmojiText = $context.CurrentFile.GetText($context.SelectedRange)
function Invoke-PlasterToolkit
{
[CmdletBinding()]
param
(
[Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context,
[Parameter(Mandatory=$true)]
[string]$Name = (Read-Host 'Please type Toolkit Name')
)

Getting Started

  • Get the Plaster Module from Plaster Github
  • Get the latest version of the VS Code Powershell Extension.
  • Create a zip file of the contents of the NewModuleTemplate folder in the Examples.
  • Set the TemplatePath variable in the ps1 file below to the path of the zip.
  • Set a Destination directory in the ps1 below.
  • Either place the code below in the Microsoft.VSCode_profile.ps1 profile or highlight and hit f8 to temporarily load it for testing.
  • Start the Command Palette by pressing f1 or ctrl+shift+P
  • type 'addi' and hit enter (Short for Show additional commands for powershell modules)
  • Enter the information prompted.
<?xml version="1.0" encoding="utf-8"?>
<plasterManifest version='0.1.0'>
<metadata>
<id>Unique-Template-Pkg-Name</id>
<!-- For display by UI's in a menu list -->
<title>New Toolkit</title>
<!-- For display by UI's in hover help -->
<description>Plaster template for creating the files for a PSAppDeploy Toolkit.</description>
<version>0.1.0</version>
<tags>Toolkit, Build</tags>