作者:cuishy | 来源:互联网 | 2023-05-18 10:29
I am at my wits end. I am new to powershell and I have tried everything I have been able to find on this subject online. What I am trying to do is print a hashtable of arrays to a file without the stupid ellipsis appearing at the end of each array value. Below is my best attempt.
我不知道该怎么做。我是powershell的新手,我已经尝试过我在网上找到这个主题的所有内容。我想要做的是将数组的哈希表打印到文件中,而不会在每个数组值的末尾出现愚蠢的省略号。以下是我最好的尝试。
# Update output buffer size to prevent clipping in output window.
if( $Host -and $Host.UI -and $Host.UI.RawUI )
{
$rawUI = $Host.UI.RawUI
$oldSize = $rawUI.BufferSize
$typeName = $oldSize.GetType( ).FullName
$newSize = New-Object $typeName (1000, $oldSize.Height)
$rawUI.BufferSize = $newSize
}
# Suposedly to allow enumeration in formatting to be unlimited
$formatenumeratiOnlimit= -1
$Dir = get-childitem c:\SomeFolderWithFiles -recurse
$List = $Dir | where {$_.extension -eq ".hash"} | where-object {$_ -ne $null}
$lookupTable = @{}
Foreach ($element in $List)
{
#Get the type of file from filename
$PSV_Type = $element.Name.Substring(0, $element.Name.indexOf("."))
#Get the date sent from filename
$Date_Sent = $element.Name.Substring($element.Name.length - 20,8)
#Populate hashTable
.....
}
$columns = @{Expression={$_.Name};Label="Date_Sent";PSV_Types";width=1000}
$lookupTable.GetEnumerator() | Sort-Object Name | Format-Table $columns | out-file C:\hashFiles.txt -width 1012
Now after all this, I still get this as a result:
在这之后,我仍然得到这个结果:
Date_Sent PSV_Types
--------- ---------
20091201 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091202 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091203 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091204 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091207 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091208 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091209 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091210 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091211 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091214 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
20091215 {31, ALLOCATIONS, AUDIT_TRAIL, BOOKS...}
Date_Sent PSV_Types --------- --------- 20091201 {31,ALLOCATIONS,AUDIT_TRAIL,BOOKS ...} 20091202 {31,ALLOCATIONS,AUDIT_TRAIL,BOOKS ...} 20091203 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091204 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091207 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091208 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091209 { 31,分配,AUDIT_TRAIL,BOOKS ...} 20091210 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091211 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091214 {31,分配,AUDIT_TRAIL,BOOKS ...} 20091215 {31,分配,AUDIT_TRAIL,BOOKS ......}
Someone wiser in the ways of powershell please tell me what I am missing. How do I get rid of these bloody ellipsis at the end and just write all the members of the array no matter how many there are? Do I have to just roll some ghetto solution by building a big string buffer and outputting that to a file or is there a better way to do this?
在powershell方面有人更聪明,请告诉我我错过了什么。如何在最后摆脱这些血腥的省略号,只要写出阵列的所有成员,无论有多少?我是否必须通过构建一个大字符串缓冲区并将其输出到文件来滚动一些贫民窟解决方案,还是有更好的方法来做到这一点?
Thanks.
谢谢。
2 个解决方案