问题描述
我正在获取服务器的固件信息,并且将其保存在变量$t
中,但是它是字符串形式.我已经(几乎)成功地将其构造为一个对象,以便将其导出为CSV,但是我需要一些帮助.
I am getting the firmware information of a server and I have it in a variable $t
but it's in the form of a string. I've (almost) successfully structured it into an object in order to export it into a CSV but there are a few kinks I need help with.
此刻我的主要问题是,似乎使用ConvertFrom-String
会将4.10
更改为4
或将2017/04/06
更改为4/6/2017 12:00:00 AM
.有什么办法解决吗?
My main problem at the moment is that it seems like using ConvertFrom-String
changes things like 4.10
to 4
or 2017/04/06
to 4/6/2017 12:00:00 AM
. Is there any way around this?
另一个问题是幽灵属性P6
出现,即使我没有明确要求它.我通过在以后将其删除来解决此问题,但我想知道是否在做任何错误的事情来生成它.
Another issue is the ghost property P6
that shows up even though I am not explicitly asking for it. I deal with this by removing it afterwards but I wonder if I'm doing something wrong to spawn it.
PS C:\Users\user> $t.Output
system> Type Status Version BuildID ReleaseDate
---- ------ ------- ------- -----------
IMM2(Primary) Active 4.10 TCOO32C 2017/04/06
IMM2(Backup) Inactive 3.70 TCOO26H 2016/11/29
UEFI(Primary) Active 2.40 TCE130J 2017/04/11
UEFI(Backup) Inactive 2.40 TCE130J 2017/04/11
DSA Active 10.2 DSALA8N 2016/10/28
system>
PS C:\Users\user> $t.Output | ConvertFrom-String -PropertyNames 'Type', 'Status', 'Version', 'Build', 'ReleaseDate' | Select-Object -Index 2,4
Type : IMM2(Primary)
Status : Active
Version : 4
Build : TCOO32C
ReleaseDate : 4/6/2017 12:00:00 AM
P6 :
Type : UEFI(Primary)
Status : Active
Version : 2
Build : TCE130J
ReleaseDate : 4/11/2017 12:00:00 AM
P6 :
谢谢.
推荐答案
从模拟输出中替换障碍元素后,ConvertFrom-Csv
可以完成工作(样本中仍然缺少时间)
After replacing the hindering elements from the simulated output,ConvertFrom-Csv
can do its job (the time still missing in your sample)
$toutput= @"
system> Type Status Version BuildID ReleaseDate
---- ------ ------- ------- -----------
IMM2(Primary) Active 4.10 TCOO32C 2017/04/06
IMM2(Backup) Inactive 3.70 TCOO26H 2016/11/29
UEFI(Primary) Active 2.40 TCE130J 2017/04/11
UEFI(Backup) Inactive 2.40 TCE130J 2017/04/11
DSA Active 10.2 DSALA8N 2016/10/28
system>
"@
$toutput -replace 'system> *' -replace '(--+\s+)+' -replace '\s{2,}',',' |
ConvertFrom-CSV | Format-Table -auto
Type Status Version BuildID ReleaseDate
---- ------ ------- ------- -----------
IMM2(Primary) Active 4.10 TCOO32C 2017/04/06
IMM2(Backup) Inactive 3.70 TCOO26H 2016/11/29
UEFI(Primary) Active 2.40 TCE130J 2017/04/11
UEFI(Backup) Inactive 2.40 TCE130J 2017/04/11
DSA Active 10.2 DSALA8N 2016/10/28
这篇关于ConvertFrom-String和ghost属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!