我想返回一个具有特定布局的对象,返回时应显示每个对象。
如果在PowerShell(而不是ISE)中运行此代码,则在函数结束之前不会看到结果。
function Main
{
for ($i = 1; $i -lt 10; $i++)
{
[pscustomobject]@{Index=$i; TimeStamp=(Get-Date)}
Sleep -Seconds 1
}
}
Main | Format-Table @{Label="Index"; Expression={$_.Index};Width=10},
@{Label="TimeStamp"; Expression={$_.TimeStamp};Width=20}
这有效,但我想要一个特定的布局。
function Main
{
for ($i = 1; $i -lt 10; $i++)
{
[pscustomobject]@{Index=$i; TimeStamp=(Get-Date)}
Sleep -Seconds 1
}
}
Main
如果在ISE中执行此脚本,为什么这种行为会有所不同?
答案 0 :(得分:0)
我的powershell配置文件中的这一行是造成这种行为的原因。
# The following function automatically adds -AutoSize for when I use Format-Wide or Format-Table
$PSDefaultParameterValues['Format-[wt]*:Autosize'] = $True