Don't use Invoke-Expression

This commit is contained in:
Jason Shirk committed 2016-07-21 09:40:03 -07:00
1 parent af27a06f89
commit d7d516a066
1 file changed
+4 -5
+4 -5
View File
@@ -47,14 +47,13 @@ function ConvertTo-CronJob ([String] $crontab) {
$cronjob
}
function Invoke-CronTab ([String] $user, [String] $arguments, [Switch] $noThrow) {
function Invoke-CronTab ([String] $user, [String[]] $arguments, [Switch] $noThrow) {
If ($user -ne [String]::Empty) {
$arguments = "-u $UserName $arguments"
$arguments = Write-Output "-u" $UserName $arguments
}
$cmd = "$crontabcmd $arguments 2>&1"
Write-Verbose $cmd
$output = Invoke-Expression $cmd
Write-Verbose "Running: $crontabcmd $arguments"
$output = & $crontabcmd @arguments 2>&1
if ($LastExitCode -ne 0 -and -not $noThrow) {
$e = New-Object System.InvalidOperationException -ArgumentList $output.Exception.Message
throw $e