Skip to content

Instantly share code, notes, and snippets.

@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" {
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
# 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" {
@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,

-ExtensionName

The Extensions Name. Accepts WildCards.

Type: String[]
Parameter Sets: ExtensionName
Aliases: 

Required: True
Position: Named
@gerane
gerane / EditorCommand.ps1
Created July 2, 2016 00:16
Place in Microsoft.VSCode_profile.ps1
Register-EditorCommand `
-Name 'ToDo.InsertToDo' `
-DisplayName 'Insert ToDo' `
-SuppressOutput `
-ScriptBlock {
param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context)
$Message = Read-Host 'Please enter Todo Message'
$ToDo = "# [$((Get-Date).ToShortDateString())] ToDo: $($Message)"
$context.CurrentFile.InsertText($ToDo, $context.CursorPosition)
}
{
"function": {
"prefix": "func",
"body": [
/* Test Comment*/
"function ${name:Verb-Noun}",
"{",
"\t[CmdletBinding()]",
"\tparam",
"\t(",
@gerane
gerane / platyps.md
Last active July 8, 2016 18:36
Getting Started with PlatyPS

Getting started with PlatyPS

  • Start by importing most recent version of module
  • I try to fill in as much information as possible in my parameter attributes before creating my innitial markdown. Having all of these filled out helps when using PlatyPS in place of comment based help. PlatyPS still has a few issues with some attributes when using Update-MarkdownHelp try to fill in all attribute like the following.
    • [SupportsWildcards()]
    • [PSDefaultValue(Help='whatever the default value is')]
    • [OutputType([if there is an outputtype])]
    • [CmdletBinding()]
    • [Alias()]
    • DefaultParameterSetName=""
  • SupportsShouldProcess
Write-Host "`nI" -NoNewLine -ForegroundColor DarkGray
Write-Host " ❤ " -NoNewLine -ForegroundColor DarkRed
Write-Host "PS>" -NoNewLine -ForegroundColor DarkGray
function global:prompt
{
$realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host $PWD.ProviderPath -NoNewLine -ForegroundColor Green
Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE