-
Notifications
You must be signed in to change notification settings - Fork 170
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
Update Get-ServiceNowTable.ps1 #22
Conversation
Added correct string to datatime casting using the local computer's culture settings.
We might want to consider merging this as soon as possible as this broke existing functionality for me. |
Hey, Gildmond, thanks for the PR. First off my apologies for not considering culture with the change. I've been testing the code in my environment and the string returned by the REST API doesn't match the pattern you're proposing. I've got a What format are your DateTime fields in? I'm not a ServiceNow admin. I consulted with one here and they're not aware of culture settings within ServiceNow. If you happen to be aware of them could you point me in the right direction? Perhaps we'd be able to get the proper format out of ServiceNow for the conversion. |
Hi Rick, Here is the error I get when running the original code.
I'm afraid I'm not sure of Service-Now's culture settings myself. |
@GilmondRoss - Short term I'm going to suggest the code change below. Would you mind testing it on your end and let me know if it makes sense? Basically if your code to use the local culture doesn't work then we attempt to use a universal format. If that doesn't work then the variable stays a string. Long term I'd like to find out how to query ServiceNow for the proper format for whatever tenant this is run against and then convert that to the local culture. Try {
# Extract the default Date/Time formatting from the local computer's "Culture" settings, and then create the format to use when parsing the date/time from Service-Now
$CultureDateTimeFormat = (Get-Culture).DateTimeFormat
$DateFormat = $CultureDateTimeFormat.ShortDatePattern
$TimeFormat = $CultureDateTimeFormat.LongTimePattern
$DateTimeFormat = "$DateFormat $TimeFormat"
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
}
Catch {
Try {
# Universal Format
$DateTimeFormat = 'yyyy-MM-dd HH:mm:ss'
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
}
Catch {
# If the local culture and universal formats both fail keep the property as a string (Do nothing)
}
} Feel free to edit your PR or let me know if you want me to do it. |
Updated with Rick's additional changes.
Hi @Rick-2CA, That seems logical, I've tested and merged your changes. Let me know if you require anything else from me. |
Appreciate the contribution. I'll get this put onto the PSGallery soon. |
Hi guys, the Service-Now Instance date format is stored in the |
@X-Guardian Confirmed. Our instance date format is set in the following table property. I'd be cautious about getting this property from there because it's a system table, and the chances of many people having access to that is questionable. If we wanted to improve on the current code, perhaps we could try getting the property from there, and if that fails, fall back to the current method? |
Sorry, yes the Looking at the |
@X-Guardian Would you be happy to make this change? |
OK, to start with I'll change the |
Added correct string to datatime casting using the local computer's culture settings.