Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input string wrong format #2

Closed
guntisratkevics opened this issue Nov 4, 2022 · 2 comments
Closed

Input string wrong format #2

guntisratkevics opened this issue Nov 4, 2022 · 2 comments

Comments

@guntisratkevics
Copy link

guntisratkevics commented Nov 4, 2022

While testing watchdog, found that it gives me error:

PS C:\Program Files\rport> PowerShell.exe -ExecutionPolicy Bypass -File .\watchdog.ps1 -Threshold 90
Cannot convert value "1667558884,94853" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Program Files\rport\watchdog.ps1:58 char:5
+     $now = ((Get-Date -UFormat %s) - [int](Get-Date -UFormat %Z) * 36 ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger
@thorstenkramm
Copy link
Contributor

@guntisratkevics Thank you so much for reporting.
You are not on an English Windows. We should have had this in mind. 🤦‍♂️

Try replacing line 58 by

#$now = ((Get-Date -UFormat %s) - [int](Get-Date -UFormat %Z) * 3600)
$now = [DateTimeOffset]::Now.ToUnixTimeSeconds()

Now, the date if fetched in a universal culture independent format.
Tested on a German Windows Server 2022.

@guntisratkevics
Copy link
Author

guntisratkevics commented Nov 4, 2022

I did it with:

#$now = ((Get-Date -UFormat %s) - [int](Get-Date -UFormat %Z) * 3600)
$now = ((Get-Date -UFormat %s).Substring(0,10) - [int](Get-Date -UFormat %Z) * 3600)

but yours is better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants