来自今天日期的最后一周数据

系统教程 行业动态 更新时间:2024-06-14 17:02:17
来自今天日期的最后一周数据 - 语法错误(Last one week data from today's date - syntax error)

我正在尝试使用PowerShell脚本从LTM获取最近7天的数据。 我没有插入特定的开始时间和结束时间,而是试图自动将数据从7天恢复到今天。 到目前为止,我尝试了以下。

$Query = New-Object -TypeName iControl.SystemStatisticsPerformanceStatisticQuery $Query.object_name = "throughput" $Query.start_time = (get-date).AddDays(-7) $Query.end_time = get-date $Query.interval = 0 $Query.maximum_rows = 0

但我收到以下错误:

Exception setting "start_time": "Cannot convert value "2/22/2017 12:26:35 PM" to type "System.Int64". Error: "Invalid cast from 'DateTime' to 'Int64'."" At line:1 char:1 + $Query.start_time = (get-date).AddDays(-7) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

I am trying to pull last 7 days of data from today's date from LTM using powershell script. Instead of inserting the specific start time and end time, I am trying to do it automatically to get data from 7 days back up till today. So far I have tried following.

$Query = New-Object -TypeName iControl.SystemStatisticsPerformanceStatisticQuery $Query.object_name = "throughput" $Query.start_time = (get-date).AddDays(-7) $Query.end_time = get-date $Query.interval = 0 $Query.maximum_rows = 0

but I am getting a following error:

Exception setting "start_time": "Cannot convert value "2/22/2017 12:26:35 PM" to type "System.Int64". Error: "Invalid cast from 'DateTime' to 'Int64'."" At line:1 char:1 + $Query.start_time = (get-date).AddDays(-7) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

最满意答案

这应该工作:

$query.start_time = [int][double]::Parse((Get-Date -Date ((get-date).AddDays(-7)) -UFormat %s))

正如我在评论中所说的那样,它期待unixtimestamp,那么我们就给了他。

This should work:

$query.start_time = [int][double]::Parse((Get-Date -Date ((get-date).AddDays(-7)) -UFormat %s))

as I said in the comments, its expecting unixtimestamp, well we gave him that.

更多推荐

本文发布于:2023-04-21 18:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/9de06c8e5f7e8b312756381c97f10bb5.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!