Hi there,
I have a script where I am importing Intune data into Assets via a POST from powershell.
I am stuck trying to get the fields that are date and time over as they are a text string when it comes into Powershell and turned into JSON and isn't recognised when it is sent over to Assets. If the Assets attribute was text it works fine, but I need to build some automations around these fields that are going to do date calcuations.
The value looks like this in the JSON
{
"objectTypeAttributeId": 385,
"objectAttributeValues": [
{
"value": "17/01/2023 14:41"
}
but it is text.
I am not sure what to do in order to get Assets to accept this as a datetime value?
When I am building the customobject that sets the fields for the JSON I do this conversion
$user | Add-Member -NotePropertyName 'Warranty Expiry Date' -NotePropertyValue $("{0:dd-MM-yyyy HH:mm}" -f $user."Warranty Expiry Date") -Force
but is Assets looking for the field in a particular format to be passed over and accepted as a Datetime?
Assets expect the format of the date to look like this:
YYYY-MM-DDTHH:mm:ssZ
And it should be in UTC time zone.
Here is an example from an import that I have that updates asset objects twice a day:
2022-11-09T22:05:01+00:00
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems like the process is falling over itself when it comes to the AM / PM side of things.
I have this function;
function Convert-StringToDatetimeJSON {
param (
[string]$inputString
)
$date = [datetime]::ParseExact($inputString, "d/MM/yyyy H:mm", $null)
$json = $date.ToString("yyyy-MM-ddTHH:mm:ss.sssZ")
return $json
}
which takes a date and time like that 17/01/2023 14:15 but then it turns that to AM and if there is this 17/01/2023 1:15 it makes that PM?
Not sure where it is getting confused getting into Assets.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Needed to offset the date;
function Convert-StringToDatetimeJSON {
param (
[string]$inputString
)
$date = [datetime]::ParseExact($inputString, "d/MM/yyyy H:mm", $null)
$dateWithOffset = [DateTimeOffset]$date
$json = $dateWithOffset.ToString("yyyy-MM-ddTHH:mm:ss.ssszzz")
return $json
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.