runtime error - Cannot find an overload for op_subtraction when subtracting datetime from datetime in powershell -


I can not get a surcharge for the error of op_subtraction error while running the code given below, Reporting that the second argument is invalid.

The defective line is:

if ($ - now - (non-job- $ $ job id.) PSBeginTime -gt [Timespain] :: From Minutes ($ KillTaskTimeMins) {

(changed below for help with debugging)

if (($ $ - $ when) -gt [Timespain]: : Minutes ($ killTaskTimeMins))

Full code:

  $ ($ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ throttle jobs are moving at any one time (@ (Get-jobs | object-object {$ _. state -akyu 'Running'}). Count-gate $ throttle) {start-Sleep- Millisecun $ $ Throttle Sleep MMS # Matter any work speculation, kill after X minutes = now $ = matching-date forwarding ($ job-in @ (Get-Job -State Running)) {# $ when = Coalesce (Get- Job -Id $ job.id) .PSBeginTime, $ now) is a custom task to make sure that it is not zero; but the writeer did not help to host, but it was not empty, however $$ = (Get-Job-$ job.id) was removed. PSBeginTime Writing-Host "Now:" + $$ # A valid date time Kna-host guess "when" + $ # when a valid date time (if $ - $ then) -gt [Taimspen] :: Seminiten ($ killTaskTimeMins)) {# & lt; - - Error order stop here - Job $ job}} Open-work-filepath GetIEVersion.ps1 -Next column $ computer # We call a custom script to get some data} # To iterate through the results of the work More stuff here; Output to CSV   

It's amazing that it works fine on my machine, but on the errors of a colleague, so I'm guessing this about my environment ...

Upgrading PowerShell 3.0 to PowerShell 2.0 solved the problem.

In the comments, as commented by @ CB, it appears job. PSBeginTime can be from the data type Nullable & lt; DateTime & gt; to DateTime .

PowerShell 3.0 includes Windows Management Framework 3.0. Download:

Comments

Popular posts from this blog

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -

java - Ajax call to jsp and jsp redirecting to further jsp -