powershell will force convert the convertfrom-json output to a string which can then be used in all string operations including filenaming

Sorry if I’m misconstruing this, but I think your end goal can be simplified by doing this

$DTCurr = (Get-Date).tostring("dd-MM-yyyy_hh:mm:ss")

or this

$DTCurr = (Get-Date).tostring("dd-MM-yyyy_hh+mm+ss")
$colonDT = $DTCurr -replace "\+",":"

but if you wanna do it your way, the reason why it’s printing that output, is because it’s doing exactly what you’re telling it to do. You’re replacing the + with an object that has a property named str with a value of :. You would need to do this instead

$colon = ('{ "str": "\uA789" }' | ConvertFrom-Json)
$DTCurr = (Get-Date).tostring("dd-MM-yyyy_hh+mm+ss")
$colonDT = $DTCurr -replace "\+",$colon.str
Echo $colonDT

If I am incorrect, and you need more assistance, let me know.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top