title: How to grab a portion of an LDAP string into a variable (Powershell)
body: <p>I am able to get the full LDAP path into a variable $strPath and it will return a result such as:</p>
  
  <blockquote>
    <p>LDAP://CN=computername,OU=City,OU=Servers,OU=###,DC=dom,DC=ain,DC=com
    or in other locations it could look like:
    LDAP://CN=computername,OU=Servers,OU=##,DC=dom,DC=ain,DC=com</p>
  </blockquote>
  
  <p>I want to return only the ##, ### or #### value (it can be either two, three or four characters) which is our district code.</p>
  
  <p>So some computer objects have a city name in their LDAP string while others do not (depending on the size of the district), and the district code can be two, three or four characters long.</p>
  
  <p>I'm guessing I want to do something like find text <strong>"Servers,OU="</strong> and remove everything including and before that and also remove text <strong>",DC=dom,DC=ain,DC=com"</strong> to get my final variable. </p>
  
  <p>Thanks in advance!</p>