【发布时间】:2020-10-16 16:35:08
【问题描述】:
我有一个文件如下。 我希望它将其转换为 CSV,并希望仅对 Drives、Drive Type、Total Space、Current allocation 和 Remaining space 项进行网格视图。
PS C:\> echo $fileSys
Storage system address: 127.0.0.1
Storage system port: 443
HTTPS connection
1: Name = Extreme Performance
Drives = 46 x 3.8T SAS Flash 4
Drive type = SAS Flash
RAID level = 5
Stripe length = 13
Total space = 149464056594432 (135.9T)
Current allocation = 108824270733312 (98.9T)
Remaining space = 40639785861120 (36.9T)
我是 Powershell 的新手,但我尝试了以下两件事的代码,但它甚至没有得到我想要的输出。
$filesys | ForEach-Object {
if ($_ -match '^.+?(?<Total space>[0-9A-F]{4}\.[0-9A-F]{4}\.[0-9A-F]{4}).+?(?<Current allocation>\d+)$') {
[PsCustomObject]@{
'Total space' = $matches['Total space']
'Current allocation' = $matches['Current allocation']
}
}
}
【问题讨论】:
-
$fileSys是单个多行字符串,还是字符串数组? -
@mathias - 我已经添加了相关文件系统的输出。
-
@GURUSINGH 我认为您误解了 Mathias 的问题。运行
$fileSys[0].GetType().FullName是否返回System.Char或System.String? -
或者,首先向我们展示您是如何创建
$fileSys的 -
$filesys 基本上是存储一个存储盒命令的输出
标签: powershell csv pscustomobject