I want to get the current date as a string in the following format:
\/Date(1411762618805)\/
I have been fighting with PowerShell and have tried the following, but it keeps wrapping the object with unwanted properties. I just need the value
Get-Date | ConvertTo-Json
# returns
{
"value": "\/Date(1411762618805)\/",
"DisplayHint": 2,
"DateTime": "Friday, September 26, 2014 4:16:58 PM"
}
Of course if you try to convert back to an object with ConvertFrom-Json you are back with a .NET Date object.
I have gotten closer with
Get-Date | Select-Object -Property Date | ConvertTo-Json
{
"Date": "\/Date(1411704000000)\/"
}
But it is still wrapped in a Date child property. At the end of the day all I want is a string with Microsoft's ugly JSON format.
I only want to use the built in .NET JSON serializers if possible.
(Get-Date | Select-Object -Property Date | ConvertTo-Json).Split('"') | Where-Object{$_ -match "\\"}. It's dirty but split into array on quotes and match the array item with a backslash (2 since it needs to be escaped in regex.)\/Date(1411704000000)\/