Powershell Select-字符串输出

Powershell Select-String output

假设根域名是 contoso.com

当我 运行 这个脚本时,它给我一个输出:

xxxxxx : contoso.com

"xxxxx"代表一些字符,包括文件名。

这些字符是什么意思,我怎样才能只得到 "contoso.com" 作为输出,而不是它前面的字符?

信息

我正在使用以下 powershell 脚本获取信息:

Get-ADDomain >> ./log.txt

Get-ADDomain给我的所有信息中,我想提取根域名,所以我使用Select-String从文本文件中提取出来,如下:

$domain = Select-String -Path ./log.txt -Pattern "RootDomain"

你的问题的答案是 xxxxxx 给你文件名和行号。

一旦这说你可以检索 RootDomain 如果它存在于 returnes 对象中使用

$(Get-ADDomain).RootDomain

您只需要了解 PowerShell Cmdlets returns 具有属性和方法的对象。 $(Get-ADDomain) 执行CmdLet Get-ADDomain.RootDomain returns 属性 RootDomain

的值

是的,$()不是必需的,(Get-ADDomain).RootDomain就够了。 或者 PowerShell 方式是 $Domain = Get-ADDomain | Select-Object -ExpandPropery RootDomain .