Skip to content

Instantly share code, notes, and snippets.

@gravejester
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravejester/b248102d164177a93bc6 to your computer and use it in GitHub Desktop.
Save gravejester/b248102d164177a93bc6 to your computer and use it in GitHub Desktop.
Convert to ScriptBlock.
function ConvertTo-ScriptBlock{
<#
.SYNOPSIS
Convert to ScriptBlock.
.DESCRIPTION
Convert input to ScriptBlock.
.EXAMPLE
Get-Content '.\scriptFile.ps1' -raw | ConvertTo-ScriptBlock
Converts a script file to a ScriptBlock.
.NOTES
Author: Øyvind Kallstad
Date: 13.03.2014
Version: 1.0
#>
param (
# Input you want converted to a ScriptBlock.
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]$InputObject
)
try {
$scriptBlock = [ScriptBlock]::Create($inputObject)
}
catch {
Write-Warning $_.Exception.Message
}
Write-Output $scriptBlock
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment