Active Directory and Powershell question

What is the difference between

$computer.distinguishedName and $computer.Get("distinguishedName")

in powershell script?
LVL 35
YZlatAsked:
Who is Participating?
 
athomsfereCommented:
$computer.distinguishedName as I recall is getting a string from the object.

$computer.Get("distinguishedName")  I believe is taking the variable and telling Powershell to search for that object and find the distinguished name.
0
 
YZlatAuthor Commented:
so basically $computer.distinguishedName is a string, and $computer.Get("distinguishedName")  is an object?
0
 
Bryan ButlerCommented:
That's how I understand it too.  Yes it is string VS. object.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Bryan ButlerCommented:
But everything is an object so both of these return the string object of the DN.  Here's some info the might help:

http://msdn.microsoft.com/en-us/library/ms676736(VS.85).aspx

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_24843064.html

0
 
athomsfereCommented:
So assuming:
$Computer = Get-QADComputer Computername
you would use $computer.distinguishedName to take that object that the search returned and find the DN String

Otherwise, if
$Computer = SomeComputerName
 then you would use
$computer.Get("distinguishedName")

to search by string for an object named SomeComputerName and then search that found object for the String of the DN
0
 
athomsfereCommented:
@developedtester

That first link id for withing VB, the syntax likely treats the objects and string parsing a little differently then PowerShell cmdlets do.
0
 
Bryan ButlerCommented:
So there is actually no difference between these.  
0
 
Bryan ButlerCommented:
PowerShell variables support the dot (.) properties.  If the object has a "get" method for the same property it will return that property.   They are all objects though.
0
 
YZlatAuthor Commented:
Thanks!
0
 
Chris DentPowerShell DeveloperCommented:
Almost everything in PS is an Object, Objects have members, which includes Properties and Methods.

In this example:

> $computer.distinguishedName and $computer.Get("distinguishedName")

$computer.DistinguishedName is a reference to a Property on an object. $computer.Get("thing") is a reference to a Method which called Get which requests a particular property from the directory cache (from AD in simple terms).

This particular object is called System.DirectoryServices.DirectoryEntry. It exposes a very small number of things as properties, the rest must be explicitly requested using Get (or GetEx in some cases).

We can see the properties exposed on this particular object in MSDN:

http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx

So we can do $computer.Name because the Name property exists. But $computer.DistinguishedName shouldn't exist, it should be blank (can't test right now, so I can't rule out PS doing something fun).

You're dealing with raw .NET types here, a less abstract interface than something like Get-QADComputer would give you; A greater degree of abstraction is typically used to simplify an interface.

> to search by string for an object named SomeComputerName and then search that found object for the String of the DN

There's no implicit searching. You'd have to have something perform the search. The properties available on any return object would be dictated by whatever performed the search and constructed the return object.

Chris
0
 
Chris DentPowerShell DeveloperCommented:
One more bit actually, if you have this:

$Computer = Get-QADComputer "SomeComputer"

Then DistinguishedName is exposed as the DN property:

$Computer.DN

Which is equivalent to the value you get from this:

$Computer = [ADSI]"LDAP://CN=SomeComputer,OU=somewhere,DC=domain,DC=com"
$Computer.Get("distinguishedName")

Quest (QAD) did a lot to simplify access things, in some cases vastly (password expiry properties are a good example of this). One of those changes was to shorten DistinguishedName to DN. Perhaps it's too prone to typos :)

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.