Created
March 13, 2020 10:44
-
-
Save Ioan-Popovici/8c3a6744f2839ab47f082acea905ad5c to your computer and use it in GitHub Desktop.
Runs a string input in the MEMCM run script feature by converting it to a script block and using Invoke-Command.
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
<# | |
.SYNOPSIS | |
Runs a script in the MEMCM run script feature. | |
.DESCRIPTION | |
Runs a string input in the MEMCM run script feature by converting it to a script block and using Invoke-Command. | |
.PARAMETER | |
Script. | |
.EXAMPLE | |
Run-CMScript.ps1 -Script 'Get-BCStatus | Select-Object -Property BranchCacheIsEnabled, BranchCacheServiceStatus' | |
.INPUTS | |
System.String. | |
.OUTPUTS | |
System.String. | |
.NOTES | |
Created by Ioan Popovici | |
.LINK | |
https://SCCM.Zone/ | |
.LINK | |
https://SCCM.Zone/GIT | |
.LINK | |
https://SCCM.Zone/ISSUES | |
.COMPONENT | |
CM | |
.FUNCTIONALITY | |
Run Script | |
#> | |
## Set script requirements | |
#Requires -Version 3.0 | |
##*============================================= | |
##* SCRIPT BODY | |
##*============================================= | |
#region ScriptBody | |
Param ( | |
[Parameter(Mandatory=$true,Position=0)] | |
[ValidateNotNullorEmpty()] | |
[Alias('scr')] | |
[string]$Script | |
) | |
Begin { | |
$ScriptBlock = [ScriptBlock]::Create($Script) | |
} | |
Process { | |
Try { | |
$Result = Invoke-Command -ScriptBlock $ScriptBlock | |
} | |
Catch { | |
$Result = $($_.Exception.Message) | |
} | |
Finally { | |
Write-Output -InputObject $Result | |
} | |
} | |
#endregion | |
##*============================================= | |
##* END SCRIPT BODY | |
##*============================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment