Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert to ScriptBlock.
function ConvertTo-ScriptBlock{
Convert to ScriptBlock.
Convert input to ScriptBlock.
Get-Content '.\scriptFile.ps1' -raw | ConvertTo-ScriptBlock
Converts a script file to a ScriptBlock.
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