2

Let's say that the Root Domain name is contoso.com

When I run this script it gives me an output along the lines of:

xxxxxx : contoso.com

The "xxxxx" represents some characters, including the file name.

What do those characters mean, and how can I make it so that I only get "contoso.com" as the output, without the characters in front of it?

Information

I am using the following powershell script to obtain information:

Get-ADDomain >> ./log.txt

From all of the information that Get-ADDomain gives me, I want to extract the Root Domain name, so I use Select-String to get it out of the text file, as follows:

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

2 Answers 2

1

The answer to your question is that xxxxxx gives you the file name and the line number.

Once this said you can retreive RootDomain if it exists in the returnes object using

$(Get-ADDomain).RootDomain

You just have to understand that PowerShell Cmdlets returns objects with properties and methods. $(Get-ADDomain) execute the CmdLet Get-ADDomain and .RootDomain returns the value of the property RootDomain

Sign up to request clarification or add additional context in comments.

1 Comment

So, to store the RootDomain in a variable, that would be: $var = $(Get-ADDomain).RootDomain
0

Yes, and $() is not required, just (Get-ADDomain).RootDomain is enough. or the PowerShell way is $Domain = Get-ADDomain | Select-Object -ExpandPropery RootDomain .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.