{"id":89,"date":"2007-03-12T14:38:10","date_gmt":"2007-03-12T22:38:10","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/03\/12\/pscx-get-adobject\/"},"modified":"2007-03-12T14:38:10","modified_gmt":"2007-03-12T22:38:10","slug":"pscx-get-adobject","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/03\/12\/pscx-get-adobject\/","title":{"rendered":"PSCX &#8211; Get-ADObject"},"content":{"rendered":"<p>I&#8217;ve started looking at the latest version of the <a href=\"http:\/\/www.codeplex.com\/Wiki\/View.aspx?ProjectName=PowerShellCX\">PowerShell Community Extensions<\/a>. One cmdlet that is sure to be popular is Get-ADobject.<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">Get-ADObject [-Class] [-Credential] [-DistinguishedName] [-Domain] [-Filter] [-GlobalCatalog] [-Scope] [-Server] [-Value] [&lt;CommonParameters&gt;]<\/font><\/p>\n<p>I&#8217;ve just started exploring its capabilities. But it makes getting objects from Active Directory a snap. This command returns a variable, $users, that contains all user object is my test domain:<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">get-adobject -distinguishedname &#8220;DC=jdhitsolutions,dc=local&#8221; -server jdhit-dc01 -class &#8220;User&#8221; -outvariable users<\/font> <\/p>\n<p>Now I can do what ever I want with this object.&nbsp; Pipe it through Get-Member to peek at all the available properties: <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">$users | get-member<\/font> <\/p>\n<p>For a quick and dirty look I can run an expression like this: <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">$users | select name,description,title<\/font> <\/p>\n<p>I can even modify an existing user: <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">$user=get-adobject -distinguishedname &#8220;CN=Bill Shakespeare,OU=Testing,DC=jdhitsolutions,Dc=local&#8221; -server jdhit-dc01<\/font> <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">$user.description=&#8221;Staff Writer&#8221;<br \/>$user.SetInfo()<\/font> <\/p>\n<p>This will update the description of the specified user object. If I re-run the first two commands I&#8217;ll see the new description. <\/p>\n<p>Here are a few other quick things I think are slick.&nbsp; I can get all objects that contain a certain value (there&#8217;s also a filter parameter which I&#8217;ll leave for you to play with): <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">get-adobject -domain JDHITSOLUTIONS -value TUser* -class user -outvariable testusers<\/font> <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">foreach ($user in $testusers) {<br \/>&gt;&gt; $user.description=&#8221;PowerShell Test User&#8221;<br \/>&gt;&gt; $user.SetInfo()<\/font> <\/p>\n<p>Here in a flash I&#8217;ve updated the description for all may user TUser accounts. <\/p>\n<p>So until PowerShell has improved Active Directory support this is probably one of the simplest and best alternatives. <\/p>\n<p>&nbsp;<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:e4c9a753-e574-4c71-826f-dc0b37b74050\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">Technorati tags: <\/span><a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\"><span class=\"sizeLess20\">PowerShell<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/PSCX\" rel=\"tag\"><span class=\"sizeLess20\">PSCX<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Get-ADObject\" rel=\"tag\"><span class=\"sizeLess20\">Get-ADObject<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/ActiveDirectory\" rel=\"tag\"><span class=\"sizeLess20\">ActiveDirectory<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Scripting\" rel=\"tag\"><span class=\"sizeLess20\">Scripting<\/span><\/a><\/div>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a0fb67cf-ee01-4196-bb51-4d74d4769926\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">del.icio.us tags: <\/span><a href=\"http:\/\/del.icio.us\/popular\/PowerShell\" rel=\"tag\"><span class=\"sizeLess20\">PowerShell<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/PSCX\" rel=\"tag\"><span class=\"sizeLess20\">PSCX<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/Get-ADObject\" rel=\"tag\"><span class=\"sizeLess20\">Get-ADObject<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/ActiveDirectory\" rel=\"tag\"><span class=\"sizeLess20\">ActiveDirectory<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/Scripting\" rel=\"tag\"><span class=\"sizeLess20\">Scripting<\/span><\/a><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve started looking at the latest version of the PowerShell Community Extensions. One cmdlet that is sure to be popular is Get-ADobject. Get-ADObject [-Class] [-Credential] [-DistinguishedName] [-Domain] [-Filter] [-GlobalCatalog] [-Scope] [-Server] [-Value] [&lt;CommonParameters&gt;] I&#8217;ve just started exploring its capabilities. But it makes getting objects from Active Directory a snap. This command returns a variable, $users, [&hellip;]<\/p>\n","protected":false},"author":3,"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":[25],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/89","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}