简体   繁体   English

如何从计划任务中获取 json 的结果

[英]How to get result as json from schedule task

I'm working on a PowerShell script which is calling C# method to enable/ disable a specific task.我正在开发一个 PowerShell 脚本,该脚本调用 C# 方法来启用/禁用特定任务。

Everything is working fine But I only want to get the Json result.一切正常但我只想得到 Json 结果。 Instead I'm getting the below result, like TaskName, TaskPath and other unwanted white space.相反,我得到了以下结果,例如 TaskName、TaskPath 和其他不需要的空白。 I'm using return $properties | ConvertTo-Json我正在使用return $properties | ConvertTo-Json return $properties | ConvertTo-Json in my PowerShell script to convert it but looks like when we do Enable-ScheduledTask PowerShell automatically added TaskPath and TaskName. return $properties | ConvertTo-Json在我的 PowerShell 脚本中进行转换,但看起来当我们执行 Enable-ScheduledTask PowerShell 时自动添加了 TaskPath 和 TaskName。

Can anyone suggestion how I can avoid TaskName/TaskPath and get only Json data in {}.谁能建议我如何避免 TaskName/TaskPath 并在 {} 中仅获取 Json 数据。

在此处输入图像描述

I got my solution.我得到了我的解决方案。 I had to use out-null to suppress the output that's it.我不得不使用 out-null 来抑制 output 就是这样。 Enable-ScheduledTask -TaskPath $TaskPath -TaskName $taskName | Enable-ScheduledTask -TaskPath $TaskPath -TaskName $taskName | Out-Null外空

I followed this: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/out-null?view=powershell-7.1我跟着这个: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/out-null?view=powershell-7.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM