{"id":315,"date":"2006-11-17T00:08:19","date_gmt":"2006-11-17T08:08:19","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2006\/11\/17\/powershell-active-directory\/"},"modified":"2006-11-17T00:08:19","modified_gmt":"2006-11-17T08:08:19","slug":"powershell-active-directory","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2006\/11\/17\/powershell-active-directory\/","title":{"rendered":"PowerShell &#038; Active Directory"},"content":{"rendered":"<p><P>I&#8217;ve had a bunch of folks ask, recently, why PowerShell has an [ADSI] type accelerator, but doesn&#8217;t have an Active Directory PSDrive. I&#8217;ve also wondered a bit, myself about why PowerShell&#8217;s [ADSI] type doesn&#8217;t work as well with WinNT queries as it does with LDAP queries.<\/P><P>To elaborate: You can, in PowerShell, do something like this:<\/P><P>[ADSI]$user = &#8220;LDAP:\/\/cn=DonJ,ou=Tech,dc=domain,dc=com&#8221;<\/P><P>And PowerShell will run out, get that user, and put the user object in the $user variable. Very cool. And you can pipe that user to Get-Member to see what it can do:<\/P><P>$user | get-member<\/P><P>However, try that with a WinNT query, rather than an LDAP query, the the Get-Member output doesn&#8217;t include the full list of methods and properties you&#8217;d expect from a WinNT object &#8211; say, a user object. Why? The answer lies not in PowerShell, but rather in the underlying .NET Framework DirectoryEntry type, which is what PowerShell is actually getting for you. Remember, PowerShell&#8217;s true functionality comes from the .NET Framework; all the cmdlets are is (oversimplifying just a bit, here) is a thin layer to make the .NET Framework a bit more task-oriented. So PoSH asks the Framework to execute your query and gives you back whatever the Framework comes up with. The Framework&#8217;s directory services classes were intended to be fairly generic, like LDAP; they don&#8217;t provide specific classes that represent the various unique WinNT-style classes. So, when you execute a WinNT query, you get back essentially the same object that an LDAP query would return. That doesn&#8217;t mean you can&#8217;t do all the things you want to with the WinNT object, mind you; you just have to do so in a more generic way. For example, you&#8217;d use Get and Put methods to view and modify user properties, rather than using direct-named properties. Just takes a bit of getting used to, really: All the functionality is still there.<\/P><P>Now about that other question: Why doesn&#8217;t PoSH let you browse Active Directory like you can the Registry, file system, certificate store, etc? In other words, why isn&#8217;t AD exposed as a PS Drive? <\/P><P>Well&#8230; it was going to be. And it almost certainly will be, someday. Earlier betas of PoSH had the beginnings of an AD PSDrive provider, but the team wasn&#8217;t able to get it up to the level of functionality they wanted in time for v1.0&#8217;s ship date. They knew this early on; the provider disappeared in the&nbsp;Beta 3 timeframe, in fact, as they made the decision to start focusing on finishing other functionality, instead. Unfortunately, even a giant like Microsoft has limited resources: You&#8217;ve got &#8220;x&#8221; number of people and &#8220;y&#8221; number of days, so you can only ship &#8220;z:&#8221; The number of features that those folks can finish in that amount of time. Sure, an AD PSDrive would be awesome &#8211; but it&#8217;ll be something to look forward to in v1.1 or v2.0 or whatever. <\/P><P>Meantime, if you haven&#8217;t done so, check out the registry PSDrive snap-in (run something like cd hkcu: to get into it). PSDrives allow PoSH to expose nearly any kind of hierarchical data as a file system, meaning registry values look like files and registry keys look like folders. The theory is that admins are already comfortable working with a file system from the command line, so why not make EVERY type of storage look like a file system? It&#8217;s a pretty bold step (for Windows; Unix systems have more or less always worked this way) and it definitely works: You only have to know ONE st of techniques for navigating storage, and it works for everything. <\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p><P>I&#8217;ve had a bunch of folks ask, recently, why PowerShell has an [ADSI] type accelerator, but doesn&#8217;t have an Active Directory PSDrive. I&#8217;ve also wondered a bit, myself about why PowerShell&#8217;s [ADSI] type doesn&#8217;t work as well with WinNT queries as it does with LDAP queries.<\/P><P>To elaborate: You can, in PowerShell, do something like this:<\/P><P>[ADSI]$user = &#8220;LDAP:\/\/cn=DonJ,ou=Tech,dc=domain,dc=com&#8221;<\/P><P>And &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,25],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-general","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}