This topic contains 8 replies, has 4 voices, and was last updated by
July 21, 2018 at 9:08 am #104884
I am using the get-smbconnection cmdlet and would like to know how is it possible to split the 6 columns that its result returned into 6 separate outputs with a delimiter
This will help me to display at will any of the 6 columns, because they will have a clear delimiter between each column and a row per result. An array in shot 🙂
An example of this cmdlet and its output:
PS C:\Windows\system32> get-smbconnection ServerName ShareName UserName Credential Dialect NumOpens ---------- --------- -------- ---------- ------- -------- Server1 ShareA DOMAIN\userA DOMAIN\userA 3.0 1 Server2 ShareB DOMAIN\userB DOMAIN\userB 3.0.2 3
I would like to be able to display it as an array with columns and delimiters.
Let me know if I am not entirely clear
Thanks a lot in advance
July 21, 2018 at 9:17 am #104887ParticipantPoints: 157Rank: Participant
May I suggest that there are better tools to display graphical tabular information rather than the text screen, such as Microsoft Excel.
You can simply pipe the output of the get-smbconnection cmdlet to export-csv
In the text screen, you can pipe the output to Format-Table with the -AutoSize switch for slightly better display
July 21, 2018 at 9:27 am #104890
Many thanks for your reply and time.
I forgot to mention that I intend to use that in a script on a script executing tool that will run it on multiple computers and therefore it needs to return the results to the standard output of the console
July 21, 2018 at 11:36 am #104893ParticipantPoints: 642Rank: Major Contributor
Another cool way to display structured data produced by a Powershell script is Out-GridView. Therefor you don't even need any other tool installed. And if needed you can make a choice in this gridview and perform further steps with the chosen data.
July 21, 2018 at 9:15 pm #104894ParticipantPoints: 392Rank: Contributor
From what you've said, it seems like the issue is more a need to store the data rather than to split up the columns.
There are several ways to go about this, but the simplest is just to export the objects to a text-based format, like CSV or json. Example:
# Uses a comma-delimited file by default, pass a string to -Delimiter to change this behaviour Get-SmbConnection | Export-Csv -Path '\\path\to\file.csv' -NoTypeInformation # Export $SMB = Import-Csv -Path '\\path\to\file.csv' # Import; if non-default delimiter, specify delimiter # Fixed format, but works better with nested datasets Get-SmbConnection | ConvertTo-Json | Set-Content -Path '\\path\to\file.json' # Export $SMB = Get-Content -Path '\\path\to\file.json' | ConvertFrom-Json # Import
July 23, 2018 at 7:34 am #104923
Thank you all
I think this is not yet the goal of what I am looking and I think it is due to a misexplaination of myself, so I will try better
The output of my script needs to be in the console, it cannot be in a file. And import it as suggested by Joel is not ideal since I am losing the delimiter needed.
The goal is more to split the columns returned by the cmdlets, in new columns displayed in the console but that have a delimiter.
As my tool will return the results of this script as follow on its UI, I need to be able to give him the information with a delimiter it can take into account, each row will be a different computer and in each column I need to have all the rows the cmdlet returned for each column for the cmdlet answer (like 3 lines in there were 3 smb shares open).
Hope I am a bit clearer
Thanks again all for your great help !
July 23, 2018 at 7:55 am #104924ParticipantPoints: 642Rank: Major Contributor
The output of my script needs to be in the console ...
May I ask why? What's the goal? What's wrong with Format-Table -Autosize? Did you try Out-GridView?
July 23, 2018 at 3:18 pm #104947ParticipantPoints: 392Rank: Contributor
Rather than export, you could instead make use of ConvertTo-Csv, which will return the same thing, just in the console (delimiters and all).
July 24, 2018 at 3:19 pm #105074
Thank you Joel,
ConvertTo-Csv did the trick !
I added the -notypeinformation | select -skip 1 at the end to remove header from my results since I don't need them
Thanks a lot all !
The final code is as follow
$result= get-smbconnection | select servername,sharename,credential,dialect | convertto-csv -notypeinformation | select -skip 1 Write-Output $result
The topic ‘How to split the results of a get command with delimiter’ is closed to new replies.