-------The first example-------
$AAA =
@‘
0.027 0.034 0.834 0.105
0.346 0.558 0.018 0.078
0.001 0.997 0.001 0.001
0.994 0.001 0.004 0.001
0.001 0.996 0.002 0.001
0.001 0.001 0.997 0.001
0.001 0.009 0.001 0.989
0.051 0.111 0.837 0.001
‘@
$t =
@‘
{Field name 1*:0.027} {Field name 2:0.034} {Field name 3:0.834} {Field name 4:0.105}
{field name 1*:0.346} 0.558 0.018 0.078
‘@
# "field name" can also be called "Property name"
$BBB = $AAA | Convertfrom-string-templatecontent $t
$bbb | Format-table-autosize
-------Command explanation-------
Convertfrom-string
function and purpose of the command:
Convert "row and column neat string" to "Pscustomobject"
PowerShell Missionary original article 2016-01-06 permitted reprint, but must retain the name and provenance, otherwise investigate legal liability convertfrom-string
After the string becomes an object property, the granularity becomes smaller, and it is easy to export to the database, Excel, to provide data for row and column conversions.
It is a magical road, ah ~ ~, the output of the character into the object ~ ~,
Since then the mountain is no longer high, buckle output is no longer difficult, characters and objects together.
How to make-------template-------
Template, the content to be broken down, with curly braces "{}" to expand the inside with a colon, the colon is preceded by your definition of "property name", after the colon is "property value"
Add "*" after the first "property name" in each line, and "template line" must have at least two lines of examples, at least two "*"
The distance from the example is not the same as the distance from the real data. Such as:
Real data:
0.027 0.034<--Here is the distance, there are n spaces-->0.834 0.105
Template:
{Field name 1*:0.027} {Field name 2:0.034}<--here is the distance, with a space, or a tab--{field name 3:0.834} 0.105
-------Other examples-------
$ Return data = @ (Netstat-an)
$ return Data-replace ' ^\s+ ' | Convertfrom-string-propertynames protocol, local IP port, external IP port, status
-------Thanks for sharing examples of friends and small buildings-------
#Requires-version 5.0
[Email protected] "
Tom
25
John doe
34
Harry
12
Zhao Liu
65
"@
[Email protected] "
{name*: Zhang San}
{age:25}
{name*: John Doe}
{age:34}
"@
$s | Convertfrom-string-templatecontent $t
Results:
Name Age
---- ---
Zhang 325
Lee 434
Wang 512
Zhao 665
"Elder" [small building] (55589641) 12:48:37
The role of convertfrom-string is to extract useful information from the text and convert it to PsObject
[Email protected] "
SSID 1: {BSSID*:ABCABC}
Network Type: Structure
Authentication: WPA2-Personal
Encryption: CCMP
BSSID 1: {macaddress:aa:bb:08:11:33:3c}
Signal: 83%
Radio Type: 802.11n
Channels: 3
Base Rate (Mbps): 1 2 5.5 11
Other rates (Mbps): 6 9 12 18 24 36 48 54
SSID 2: {bssid*:d efdef}
Network Type: Structure
Authentication: WPA2-Personal
Encryption: CCMP
BSSID 1: {MACADDRESS:CC:DD:E4:7A:C4:D8}
Signal: 64%
Radio Type: 802.11n
Channels: 6
Base Rate (Mbps): 1 2 5.5 11
Other rates (Mbps): 6 9 12 18 24 36 48 54
"@
Netsh wlan show Network Mode=bssid | Convertfrom-string-templatecontent $t
"Elder" [small building] (55589641) 12:55:47
Results:
Bssid MACAddress
----- ----------
Abc-internet b4:a4:e3:65:ea:60
Sannongziben1 00:22:aa:ad:0b:44
ABCD 64:f6:9d:d5:e4:40
Abc-byod 64:f6:9d:d5:e4:42
Abc-guest 64:f6:9d:d5:e4:41
Sharmoon 78:a1:06:58:6d:82
sannongziben666 00:22:aa:ad:1c:d8
TP-LINK-88SL EC:26:CA:30:78:DC
ABCDE 00:1f:33:de:22:ae
Tp-linklongten 14:75:90:BD:9A:CC
Weijin 14:75:90:43:96:fe
Ctc-inter 14:cf:92:62:76:d4
d-link_dir-600m 34:08:04:7D:2A:B1
Study on the convertfrom-string command in powershell5.0