Skip to content

Commit 5912af3

Browse files
authored
Update Get-ServiceNowTable.ps1
Added correct string to datatime casting using the local computer's culture settings.
1 parent 0b55544 commit 5912af3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ServiceNow/Public/Get-ServiceNowTable.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ function Get-ServiceNowTable
8585
ForEach ($SNResult in $Result) {
8686
ForEach ($Property in $ConvertToDateField) {
8787
If (-not [string]::IsNullOrEmpty($SNResult.$Property)) {
88-
$SNResult.$Property = [datetime]$SNResult.$Property
88+
# 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
89+
$CultureDateTimeFormat = (Get-Culture).DateTimeFormat
90+
$DateFormat = $CultureDateTimeFormat.ShortDatePattern
91+
$TimeFormat = $CultureDateTimeFormat.LongTimePattern
92+
$DateTimeFormat = "$DateFormat $TimeFormat"
93+
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
8994
}
9095
}
9196
}
9297

9398
# Return the results
9499
$Result
95-
}
100+
}

0 commit comments

Comments
 (0)