{"id":1011,"date":"2012-05-25T09:00:27","date_gmt":"2012-05-25T13:00:27","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1011"},"modified":"2012-05-24T20:24:05","modified_gmt":"2012-05-25T00:24:05","slug":"find-upper-range-of-ad-attributes","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/find-upper-range-of-ad-attributes\/","title":{"rendered":"Find upper range of AD attributes"},"content":{"rendered":"<p>The other day I was working on a powershell script to copy specific Active Directory attributes to a SQL database.  I wanted to see if the destination SQL fields (which were varchar 100) would be able to contain the attributes, but I didn&#8217;t know the maximum lengths of the text in Active Directory.  I hacked together a quick LDAP query to get all of the &#8216;rangeUpper&#8217; values for each attribute.  Here is that code:<\/p>\n<pre><code class=\"language-powershell\">\r\n$myReport=@()\r\n\r\n$Base = \"<LDAP:\/\/CN=Schema,CN=Configuration,dc=bwuch,dc=local>\"\r\n$Filter = \"(&(objectCategory=attributeSchema)(rangeUpper=*))\"\r\n$Attributes = \"distinguishedName\"\r\n$Scope = \"subtree\"\r\n$Query = \"$Base;$Filter;$Attributes;$Scope\"\r\n$Connection = New-Object -ComObject \"ADODB.Connection\"\r\n$Command = New-Object -ComObject \"ADODB.Command\"\r\n$Connection.Open(\"Provider=ADsDSOObject;\")\r\n$Command.ActiveConnection = $Connection\r\n$Command.Properties.item(\"Size Limit\").value = 90000\r\n$Command.Properties.item(\"Page Size\").value = 90000\r\n$Command.CommandText = $Query\r\n$Recordset = $Command.Execute()\r\nDo {\r\n\t$dn = $Recordset.Fields.item(\"distinguishedName\") \r\n\t$dn = $dn.value\r\n\t\r\n\t$objSchema = Get-ADObject $dn\r\n\t\r\n\t$myReport+= New-Object psobject -Property @{\r\n\t\tLDAPAttribute = [string]$objSchema.lDAPDisplayName\r\n\t\tMaxValue = [string]$objSchema.rangeUpper\r\n\t}\r\n\t\r\n\tif ($Recordset.eof -ne $true) {$Recordset.MoveNext()}\r\n}\r\nUntil ($Recordset.eof)\r\n$Connection.Close > $null\r\n$myReport | Sort LDAPAttribute\r\n<\/code><\/pre>\n<p>Hope this can help you too!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I was working on a powershell script to copy specific Active Directory attributes to a SQL database. I wanted to see if the destination SQL fields (which were varchar 100) would be able to contain the attributes, &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/find-upper-range-of-ad-attributes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"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":[3],"tags":[],"class_list":["post-1011","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1011"}],"version-history":[{"count":4,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1011\/revisions"}],"predecessor-version":[{"id":1016,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1011\/revisions\/1016"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}