[英]Extract a value from a ScheduledTask array in Powershell
everyone. 大家。 I am newbie to Powershell.
我是Powershell的新手。 So your help is much appreciated.
因此,非常感谢您的帮助。
My question is the following. 我的问题如下。 I have a powershell small script that provides me with server Start, Stop, Kill ... tasks.
我有一个Powershell小脚本,可为我提供服务器启动,停止,终止...任务。
Here's the command 这是命令
PS P:\> Get-ScheduledTask -TaskPath "*$someString*" | Get-ScheduledTaskInfo | Select TaskName,LastRunTime,NextRunTime
TaskName LastRunTime NextRunTime
-------- ----------- -----------
Archive 10/14/2017 7:00:00 AM 10/21/2017 7:00:00 AM
Kill 10/15/2017 12:50:50 PM 10/22/2017 12:50:50 PM
Restart 10/20/2017 12:00:00 AM 10/23/2017 12:00:00 AM
Start 10/15/2017 1:00:00 PM 10/22/2017 1:00:00 PM
Stop 10/13/2017 5:30:30 PM 10/20/2017 5:30:30 PM
I would like to extract the value of LastRunTime that corresponds to Start and the value of NextRunTime that corresponds to stop, and have them converted to a String. 我想提取对应于Start的LastRunTime值和对应于stop的NextRunTime值,并将它们转换为String。
Thank you. 谢谢。
Not very useful in the requested OP format, but here you go 在要求的OP格式中不是很有用,但是您可以在这里
C:\> $TaskNames = "Start","Stop"
C:\> $data = Get-ScheduledTask -TaskName $TaskNames | Get-ScheduledTaskInfo
C:\> [string]"$(($data | sort)[0].LastRunTime) $(($data | sort)[1].NextRunTime)"
10/20/2017 08:15:15 10/21/2017 09:16:16
this will only work right if your task names are actually in alphabetical order. 仅当您的任务名称实际上按字母顺序排列时,此方法才有效。 Change the indexes (numbers in
[]
) if the sort comes out in a different order. 如果排序顺序不同,请更改索引(
[]
数字)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.