Ok, just a small one today. You won’t save any typing with this, as the actual code is just one line, and not much longer than the function name. But I think it looks nicer, and it’s easier to remember. Besides, it looks more like “proper” PowerShell.
This function takes input and converts it to a ScriptBlock. Nothing more, nothing less.
This file contains 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
|Convert to ScriptBlock.|
|Convert input to ScriptBlock.|
|Get-Content '.\scriptFile.ps1' -raw | ConvertTo-ScriptBlock|
|Converts a script file to a ScriptBlock.|
|Author: Øyvind Kallstad|
|# Input you want converted to a ScriptBlock.|
|[Parameter(Mandatory = $true, ValueFromPipeline = $true)]$InputObject|
|$scriptBlock = [ScriptBlock]::Create($inputObject)|