Powershell 2.0格式列表输出到JSON吗? [英] Powershell 2.0 Format-list output to JSON?

查看:129
本文介绍了Powershell 2.0格式列表输出到JSON吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PS B:\abrabackups> . C:\ps\ConvertTo-JSON.ps1
PS B:\abrabackups> Get-ItemProperty -Path .\AbraSuite01.03.2014 | select Name,CreationTime | ConvertTo-JSON

这给了我:(为清楚起见而格式化)

{
 "CreationTime": "2014-01-03T16:48:36", 
 "Name": "AbraSuite01.03.2014"
}

这很好,但是假设我希望我的日期以JSON字符串的其他格式显示,无论如何都可以在powershell中执行此操作,并且仍然使用我的

Well that's all well and good, but suppose I want my dates in a different format in the JSON string, is there anyway to do this in powershell and still use my shoehorned ConvertTo-JSON.ps1 for powershell 2.0?

推荐答案

使用

$_.CreationTime.ToShortDateString()替换为获取日期格式所需的任何内容-但是这里的关键是使用$_.CreationTime来获取管道中对象的创建时间.

Replace $_.CreationTime.ToShortDateString() with whatever you need to get the date format you're after - but the key here is to use $_.CreationTime to grab the creation time of the object in the pipeline.

这篇关于Powershell 2.0格式列表输出到JSON吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆