0

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
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
  • well, the error says it, it is probably looking for unix time, try this: `$date = (Get-Date).AddDays(-7); [int][double]::Parse((Get-Date -Date $date -UFormat %s))` – 4c74356b41 Mar 01 '17 at 18:17
  • I need to specify start_time and end_time, when use it i am getting an error. I have modified the syntax that you provided as follows. $Query.start_time = (get-date).AddDays(-7); [int][double]::Parse((Get-Date -Date $Query -UFormat %s)) and error is The property 'start_time' cannot be found on this object. Verify that the property exists and can be set. ..... I am new to scripting still trying to figure out – user2769144 Mar 01 '17 at 18:51
  • no, you are doing it wrong. `$Query.start_time = [int][double]::Parse((Get-Date -Date ((get-date).AddDays(-7)) -UFormat %s))` – 4c74356b41 Mar 01 '17 at 19:01
  • Thanks. I tried this but it giving me an error $Query.start_time = [int][double]::Parse((Get-Date -Date ((get-date).AddDays(-7)) -UFormat %s)) The property 'start_time' cannot be found on this object. Verify that the property exists and can be set. .......... and end time ......... $Query.end_time = [int][double]::Parse((Get-Date -Date (get-date) $Query -UFormat %s)) Get-Date : A positional parameter cannot be found that accepts argument '3/1/2017 2:06:51 PM'. – user2769144 Mar 01 '17 at 19:16
  • well, you obviously don't know what you are doing, do a `$query | gm` and post output in your answer – 4c74356b41 Mar 01 '17 at 19:18
  • nono, edit your answer, why is $query object an datetime object? you did something wrong – 4c74356b41 Mar 01 '17 at 19:27
  • I am getting the same result from $Query | gm .. I posted the whole script here http://stackoverflow.com/q/40727333/2769144 – user2769144 Mar 01 '17 at 19:39
  • can we continue in the chat? – 4c74356b41 Mar 01 '17 at 19:46
  • Sure, but I have 8 reputation, and getting message not yet enough to chat – user2769144 Mar 01 '17 at 19:52

1 Answers1

0

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.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141