Last active
August 29, 2015 14:07
-
-
Save gravejester/b248102d164177a93bc6 to your computer and use it in GitHub Desktop.
Convert to ScriptBlock.
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
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