gpt4 book ai didi

powershell - PowerShell格式表希望将属性用作列标题

转载 作者:行者123 更新时间:2023-12-03 00:59:49 29 4
gpt4 key购买 nike

使用此代码:

$l | ForEach-Object -Process {
$p = ($_.Folder + '\' + $_.Filename).Replace("{yymmdd}", "190911")
if (Test-Path $p) {
Write-Output @{Portfolio = $_.Portfolio; Path = $p; CreateTime = (Get-ChildItem $p).CreationTime}
} else {
Write-Output @{Portfolio = $_.Portfolio; Path = $p; CreateTime = "not found"}
}
} | Format-Table

我得到:

名称值
---- -----
路径S:\ Data \ 190911 \ LN190911.txt
投资组合贷款
CreateTime 9/12/2019 6:29:47 AM
路径S:\ Data \ 190911 \ SL190911.txt
投资组合贷款
CreateTime 9/12/2019 6:29:46 AM

我希望名称是列标题,而值要出现在每列下。我该如何完成?

最佳答案

这仅仅是将哈希表转换为对象的问题。删除Write-Output,并在哈希表之前添加[pscustomobject]类型,它将执行您想要的操作。

$l | ForEach-Object -Process {
$p = ($_.Folder + '\' + $_.Filename).Replace("{yymmdd}", "190911")
if (Test-Path $p) {
[PSCustomObject]@{Portfolio = $_.Portfolio; Path = $p; CreateTime = (Get-ChildItem $p).CreationTime}
} else {
[PSCustomObject]@{Portfolio = $_.Portfolio; Path = $p; CreateTime = "not found"}
}
} | Format-Table

关于powershell - PowerShell格式表希望将属性用作列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57914137/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com