来自今天日期的最后一周数据 - 语法错误(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 : ExceptionWhenSettingI 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 = 0but 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.
更多推荐
发布评论