由于我添加了这段代码(因为有两个浮点数就足够了),所以我的散列表得到了指示。谢谢。
@{Name="Megas";Expression={"{0:N2}" -f $($_.Length / 1MB)}}从原点
@{Name="Megas";Expression={$_.Length / 1MB}}期望产出:
Ficheros Megas(top rigth)
-------- -----
\desktop\someting.exe 1.20实际输出,正在造成倾斜的路径..。
Ficheros Megas(at the middle)
-------- -----
\desktop\sometin... 1.20代码:
param([string]$pc,[string]$user)
$w7="\\$pc\c$\users\$user\desktop"
if(Test-Path $w7){
Get-ChildItem -Recurse -force -Include *.* -exclude *.ini, *.lnk, *.url, *.db, *.txt $w7 -ErrorAction "SilentlyContinue" | ls | Select-Object -ErrorAction "SilentlyContinue" @{Name="Ficheros";Expression={$_.FullName -replace '.*?(\\Desktop.*)', '$1'}}, @{Name="Megas";Expression={$_.Length / 1MB}}
}
else{
Write-Host -BackgroundColor White -ForegroundColor Red "FAIL"
}我试过了,但是得到了错误“Select.等等使用的哈希表不支持对齐指令”
Select-Object format-table @{Name="Megas";Expression={$_.Length / 1MB};alignment="right"}发布于 2014-06-24 15:19:43
正如@AdilHindistan在评论中所建议的那样,您应该尝试使用Format-Table -AutoSize来修复可视输出。Select-Object用于提取(创建自定义对象),只有导出对象之前所需的属性。当您需要为“可视结果”创建自定义视图时,应该使用Format-Table。所以试着:
param([string]$pc,[string]$user)
$w7="\\$pc\c$\users\$user\desktop"
if(Test-Path $w7){
Get-ChildItem -Recurse -force -Include *.* -exclude *.ini, *.lnk, *.url, *.db, *.txt -Path $w7 -ErrorAction "SilentlyContinue" |
Format-Table -AutoSize -ErrorAction "SilentlyContinue" @{Name="Ficheros";Expression={$_.FullName -replace '.*?(\\Desktop.*)', '$1'}}, @{Name="Megas";Expression={$_.Length / 1MB}}
}
else{
Write-Host -BackgroundColor White -ForegroundColor Red "FAIL"
}您的示例中还有一个不必要的ls(Get-ChildItem)。您已经在第一个Get-ChildItem调用中使用了Get-ChildItem。
https://stackoverflow.com/questions/24389547
复制相似问题