Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Active Directory and Powershell question

Posted on 2011-05-04
11
Medium Priority
?
594 Views
Last Modified: 2012-05-11
What is the difference between

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

in powershell script?
0
Comment
Question by:YZlat
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Accepted Solution

by:
athomsfere earned 500 total points
ID: 35692575
$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
 
LVL 35

Author Comment

by:YZlat
ID: 35692589
so basically $computer.distinguishedName is a string, and $computer.Get("distinguishedName")  is an object?
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35692731
That's how I understand it too.  Yes it is string VS. object.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35692929
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
 
LVL 14

Expert Comment

by:athomsfere
ID: 35692970
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
 
LVL 14

Expert Comment

by:athomsfere
ID: 35692998
@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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35693019
So there is actually no difference between these.  
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35693134
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
 
LVL 35

Author Closing Comment

by:YZlat
ID: 35693171
Thanks!
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35693216
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
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35693315
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question