This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1. in your logging module, you could have a function like this that takes a dependency called Destination. | |
function Write-ToLog{ | |
param( | |
[Parameter(Mandatory=$true)] $Destination, | |
[Parameter(Mandatory=$true)] [System.String] $Message | |
) | |
try { | |
$Destination.Write() | |
} | |
catch { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# Author: Steve Rathbone | |
May 2015 | |
#> | |
$sb = { | |
[string]$myPrivateVariable = "Hello World!" | |
function Say-HelloWorld([string]$s) { | |
write-output $s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this is in no way production ready code that should be used in a live system, | |
#however it explains the basic elements that make the connection possible. | |
import clr, System | |
clr.AddReference("System.Management.Automation") | |
from System.Management.Automation import Runspaces | |
myrunspace = Runspaces.RunspaceFactory.CreateRunspace() | |
myrunspace.Open() | |
pipeline = myrunspace.CreatePipeline() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The string "foo" below explicitly states that $obj is instantiated with a real .NET concrete type (String) underneath, | |
#and that the object $obj is subsequently turned into a new type of PSObject and is not a new extension method applied to the | |
#string class. | |
$obj = "foo" | Add-Member -MemberType ScriptMethod -Value { | |
param( $first, $second) | |
"first is $first, second is $second" | |
} | |
-Name DoStuff -PassThru; $obj.DoStuff('abc', '123') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$psise.CurrentFile | Add-Member ScriptMethod "GetFileExtension" {return [System.IO.Path]::GetExtension($psISE.CurrentFile.DisplayName)} |