mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Don't use Invoke-Expression
This commit is contained in:
1 parent
af27a06f89
commit
d7d516a066
1 file changed
+4
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user