Fix RemoveSheduledTask()

This commit is contained in:
Yorick Barbanneau 2018-03-23 13:35:43 +01:00
parent cab76871f2
commit 28853e6b0a

View file

@ -95,26 +95,17 @@ function RemoveScheduledTask () {
)
if ( $params.ContainsKey('file') ) {
Get-Content $params.file | foreach {
try {
$line = $_
RemoveScheduledTask -task $( Get-ScheduledTask -TaskName $line -ErrorAction Stop)
}
catch [Microsoft.PowerShell.Cmdletization.Cim.CimJobException]{
Write-Host -ForegroundColor Yellow "`tScheduled Task $line not found"
}
catch {
Write-Host -NoNewline -ForegroundColor Red "`tError in RemoveSheduledTask`n`t"
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
}
RemoveScheduledTask @{name=$_}
}
}
elseif ( $params.ContainsKey('name') ) {
$command = "Get-ScheduledTask -ErrorAction Stop -TaskName `"$($params.name)`""
if ($params.path) {
if ($params.ContainsKey('path') -and $params.path -ne '') {
$command += " -TaskPath `"$($params.path)`""
}
else { $params.path="" }
try {
$task = $(Invoke-Expression $command)
$task = Invoke-Expression $command
Write-Host -NoNewline "`tRemove task $($param.name) : "
$task | Unregister-ScheduledTask -ErrorAction SilentlyContinue -Confirm:$false
Write-Host -ForegroundColor Green "done"
@ -257,7 +248,7 @@ function UninstallModernApp {
elseif ( $params.ContainsKey('name') ) {
Write-Host -NoNewLine "`tUninstall $($params.name) :"
try {
Get-AppxPackage -AllUsers | Where-Object { $_.name -like "*$($params.name)*" } | Remove-AppxPackage -ErrorAction Continue -ErrorVariable $Error | Out-Null
Get-AppxPackage -AllUsers | Where-Object { $_.name -like "*$($params.name)*" } | Out-Null
Write-Host -ForegroundColor Green "done"
}
catch {
@ -378,7 +369,7 @@ function KillProcess {
)
Write-Host -NoNewLine "`tKilling $($params.name) : "
try {
Stop-Process $(Get-Process $params.name)
Stop-Process $(Get-Process $params.name) | Out-Null
Write-Host -ForegroundColor Green "Done"
}
catch {