当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 字符串属性带来更多乐趣

作者:精品下载站 日期:2024-12-14 07:41:58 浏览:16 分类:玩电脑

字符串属性带来更多乐趣


前几天,我发布了一篇有关将运行命令行工具可能获得的字符串属性转换为 PowerShell 命名属性的文章。我继续尝试它。这是一些关于如何使用它的代码。

$raw = qprocess
$properties = $raw[0] -split "\s{2,}" | Convert-StringProperty 
$raw | select -Skip 1 | foreach {
 #split each line
 $data = $_ -split "\s{2,}"
 $hash=[ordered]@{}
 for ($i=0;$i -lt $properties.count;$i++) {
   $hash.Add($properties[$i],$data[$i])
 }
 [pscustomobject]$hash
}

我最终得到这样的输出:

Username    : >jeff
Sessionname : console
Id          : 1
Pid         : 3044
Image       : conhost.exe

Username    : >jeff
Sessionname : console
Id          : 1
Pid         : 4848
Image       : chrome.exe

最好清理这些值并删除“

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯