List a hash table of arrays in Powershell

I am on my way. I'm new to PowerShell, and I tried everything I could find on the subject on the Internet. What I'm trying to do is print a hash table of arrays in a file without the dumb ellipsis appearing at the end of each array value. Below is my best attempt.

# 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";width=12}, @{Expression={$_.Value};Label="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, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091202 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091203 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091204 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091207 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091208 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091209 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091210 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091211 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091214 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}
20091215 {31, DISTRIBUTIONS, AUDIT_TRAIL, BOOKS ...}

Someone wiser in powershell methods, please tell me what I am missing. How do I get rid of these bloody ellipses at the end and just write all the members of the array no matter how many there are? Should I just run some ghetto solution by building a large string buffer and outputting it to a file, or is there a better way to do this?

Thanks.

+7
source share
2 answers

For this reason you should not use Out-File, it goes through the default formatting mechanism. What you want to use is Set-Content / Add-Content, like this.

 $lookupTable.GetEnumerator() | Sort-Object Name | ForEach-Object {"{0}`t{1}" -f $_.Name,($_.Value -join ",")} | Add-Content C:\hashFiles.txt 
+8
source

Well, powershell will not play well. This is the only thing I could work:

 $lookupTable = $lookupTable.GetEnumerator() | Sort-Object Name foreach ($element in $lookupTable) { $msg = $element.Key + "`t" foreach ($psv in $element.Value) { $msg = $msg + $psv + "," } #remove last comma and add newline $msg = $msg.SubString(0, $msg.length -1) + "`n" Add-Content C:\hashFiles.txt $msg } 
+2
source

All Articles