模式匹配Powershell - Multiline

时间:2018-04-06 09:53:31

标签: pattern-matching

$EvtMessage= @"
A member was removed from a security-enabled global group.

Subject:
	Security ID:		S-1-5-21-1232435678-3215674231-8564287451-324516
	Account Name:		tstact.ntt.admin
	Account Domain:		DT
	Logon ID:		0x1E3363AEE

Member:
	Security ID:		S-1-5-21-1523435678-3215674231-8564287451-324516
	Account Name:		CN=DT DEST02,OU=NoStandard,OU=Users,OU=My Org B2B TEST,DC=DT,DC=ad,DC=local

Group:
	Security ID:		S-1-5-21-1523435678-3215674231-8564287451-324516
	Group Name:		TSK-DT-S-D-SRVAdmin
	Group Domain:		DT

Additional Information:
	Privileges:	
"@

我需要提取上面“ tstact.ntt.admin ”位置的任何字符串(在主题:下,而不是成员: )使用 -Match 选择字符串。你能帮我解决一下PowerShell正则表达式吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

可能不是完美的解决方案,但我最终得到了以下内容:

@($ EvtMessage -split [environment] :: NewLine)[4] -match'。帐户名称:(?。)$'

<强> $ matches.AccountName

此解决方案假定消息结构的格式(就各行而言)不会更改。手指交叉......

相关问题