Skip to content

Commit 730ae64

Browse files
authored
Pass string array to ParseExact to increase success chance (#266)
Passing a string[] to ParseExact means that an exception is less likely to be thrown.
1 parent e38eaea commit 730ae64

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,12 @@ function Invoke-ServiceNowRestMethod {
249249
$CultureDateTimeFormat = (Get-Culture).DateTimeFormat
250250
$DateFormat = $CultureDateTimeFormat.ShortDatePattern
251251
$TimeFormat = $CultureDateTimeFormat.LongTimePattern
252-
$DateTimeFormat = "$DateFormat $TimeFormat"
252+
$DateTimeFormat = [string[]]@("$DateFormat $TimeFormat", 'yyyy-MM-dd HH:mm:ss')
253253
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
254254
}
255255
Catch {
256-
Try {
257-
# Universal Format
258-
$DateTimeFormat = 'yyyy-MM-dd HH:mm:ss'
259-
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
260-
}
261-
Catch {
262-
# If the local culture and universal formats both fail keep the property as a string (Do nothing)
263-
$null = 'Silencing a PSSA alert with this line'
264-
}
256+
# If the local culture and universal formats both fail keep the property as a string (Do nothing)
257+
$null = 'Silencing a PSSA alert with this line'
265258
}
266259
}
267260
}

0 commit comments

Comments
 (0)