简体   繁体   English

从表中获取特定值

[英]Get specific value from table

I have a script that gets an email address from a .msg file and I have gotten most of the script to work the way I want it. 我有一个脚本从.msg文件获取电子邮件地址,并且我已经使大多数脚本按我想要的方式工作。

So for this string: 所以对于这个字符串:

(Select-String -InputObject $SEMFINAL -Pattern '\w+@\w+\.\w+' -AllMatches).Matches

I get: 我得到:

Index    : 0
Length   : 15
Value    : email@email.com

How can I filter the results to only get the data for the Value in the table? 如何过滤结果以仅获取表中“值”的数据?

This might not be the most graceful solution, but would this work?: 这可能不是最合适的解决方案,但这行得通吗?:

$SEMFINAL = "Hello my address is bob@example.com Thanks. P.S. You can also reach me at robert@example.com" 
(Select-String -InputObject $SEMFINAL -Pattern '\w+@\w+\.\w+' -AllMatches).matches | select value

Output ( Value property of the match objects): 输出(匹配对象的Value属性):

Value
-----
bob@example.com
robert@example.com

To expand the properties to their actual value, change the last portion to 要将属性扩展为实际值,请将最后一部分更改为

| select -Expand value

to the end. 到最后。

(Select-String -InputObject $SEMFINAL -Pattern '\w+@\w+\.\w+' -AllMatches).matches | select -Expand value

Output: 输出:

bob@example.com
Robert@example.com

I just recently learned about objects and hash tables, which I think is what is going on here. 我最近才了解对象和哈希表,我认为这是正在发生的事情。 You need to create an object with the values you want assigned to it. 您需要使用要为其分配值的对象来创建对象。 Otherwise it will only give you the length of the values. 否则,它只会给您值的长度。

So something like: 所以像这样:

 $EmailInput = (Select-String -InputObject $SEMFINAL -Pattern '\w+@\w+\.\w+' -AllMatches).Matches
 $Email = @{
            "Email" = $EmailInput
        }
        $EmailObject = New-Object -TypeName psobject -Property $Email

I'm still learning, so you may need to mess with it a bit (or a lot), but I think you'll need to put that info into an object if you want to read the actual values instead of just lengths. 我仍在学习,所以您可能需要对其进行一些(或很多)改动,但是我想如果您想读取实际值而不是长度,则需要将该信息放入对象中。

If someone else understands objects better please correct me. 如果其他人更好地理解物体,请纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM