Strings are hard, because they aren’t ALWAYS in the same format, BUT if they are, you can do some things. If you’re final string is always inside double quotes, the below works.
Thank you for all answer. Let me explain a more about the script. My need is get some information for an equipment with SNMPWalk. When I run the command (walk), the result is an array. See below:
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777216 = STRING: “54321C013217A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777217 = STRING: “12345F100417A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777472 = STRING: “54321C012817A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777473 = STRING: “12345F100317A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777728 = STRING: “12345F100017A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777729 = STRING: “12345F100617A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777730 = STRING: “12345F1TESTE2”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777985 = STRING: “12345F100717A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16777986 = STRING: “12345F10TESTE”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16778241 = STRING: “12345F100817A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16778497 = STRING: “12345F100917A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16778753 = STRING: “12345F101017A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16779009 = STRING: “12345F101117A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16779265 = STRING: “12345F101217A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16779521 = STRING: “12345F101317A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16779777 = STRING: “12345F102117A”
.1.3.6.1.4.1.3709.3.6.2.1.1.5.16780033 = STRING: “12345F102417A”
I would like to get only value between “”.
The split almost work, but it get only first line.
I was unable to edit the above reply, but try this:
$string = '.1.3.6.1.4.1.3709.3.6.2.1.1.5.16780033 = STRING: "12345F102417A"'
$pattern = '^.*"(?(.*))"$' #Your editor is removing the less than name greater than part of this which should be directly after the ?.
if ($string -match $pattern) {
Write-Host $matches.name
}
Due to a quirk in your HTML editor I cannot write the above correctly. This is what goes directly after the ? LESS THAN name GREATER THAN (no spaces).
I don’t have solved that issue yet. The most problem is that the result (string between “”) has the various size. Some have 8 characters, and some other have plus or minus.
That’s pretty easy, assuming your data come as separate lines (that is why I am doing the -split on it), all you need to do is replace everything that is not in the last quotes:
There is a simple snmp powershell module here. It doesn’t resolve hostnames, but for simple strings it should be straighforward. PowerShell Gallery | SNMP 1.0.0.1
It looks like what you really want to do is use regex to parse the strings and make PowerShell objects out of them so you can then work with the data in a more powershell way to filter or grab the data you want.