Windows Vista Forums

Split function
  1. #1


    IT Staff Guest

    Split function

    How do i call from .net ?





      My System SpecsSystem Spec

  2. #2


    IT Staff Guest

    Re: Split function

    $sam = "ntid"
    $searcher=New-Object DirectoryServices.DirectorySearcher
    $searcher.Filter="(&(objectcategory=person)(objectclass=user)(samaccountname="+$sam+"))"
    $results=$searcher.FindOne()
    Write-Host $results.properties.homemdb

    The homemdb properties shows

    CN=607MB-SG2-MBS2-Std,CN=607MB-SG2,CN=InformationStore,CN=D1SNX607MB,CN=Servers,
    CN=Second Administrative Group,CN=Administrative
    Groups,CN=NOL-APL,CN=Microsoft

    I split by doing the following :

    $a = $results.properties.homemdb
    $b = $a.split(",")

    But it does not work, why ?









    "IT Staff" <jkklim@xxxxxx> wrote in message
    news:eIT%236NiFIHA.3548@xxxxxx

    > How do i call from .net ?
    >


      My System SpecsSystem Spec

  3. #3


    Jeff Guest

    Re: Split function

    On Oct 24, 4:51 pm, "IT Staff" <jkk...@xxxxxx> wrote:

    > How do i call from .net ?
    System.String has a Split method which you can use on any string in
    PowerShell:

    PSH$ $string = "this is a string with spaces"
    PSH$ $string.Split( " " )
    this
    is
    a
    string
    with
    spaces

    If you want to split a string with a regular expression,
    System.Text.RegularExpressions.Regex has a static Split method for
    that ([regex] is a shortcut for the full name of the Regex type):

    PSH$ [regex]::Split( $string, "\s" )
    this
    is
    a
    string
    with
    spaces


    Jeff


      My System SpecsSystem Spec

  4. #4


    IT Staff Guest

    Re: Split function

    think i manage to do it by doing the following :

    $a = [string] $results.properties.homemdb
    $b = $a.split(",")

    write-host $b[0] #to get the element i need


    "Jeff" <jeff.hillman@xxxxxx> wrote in message
    news:1193221576.719535.318790@xxxxxx

    > On Oct 24, 4:51 pm, "IT Staff" <jkk...@xxxxxx> wrote:

    >> How do i call from .net ?
    >
    > System.String has a Split method which you can use on any string in
    > PowerShell:
    >
    > PSH$ $string = "this is a string with spaces"
    > PSH$ $string.Split( " " )
    > this
    > is
    > a
    > string
    > with
    > spaces
    >
    > If you want to split a string with a regular expression,
    > System.Text.RegularExpressions.Regex has a static Split method for
    > that ([regex] is a shortcut for the full name of the Regex type):
    >
    > PSH$ [regex]::Split( $string, "\s" )
    > this
    > is
    > a
    > string
    > with
    > spaces
    >
    >
    > Jeff
    >


      My System SpecsSystem Spec

  5. #5


    Jeff Guest

    Re: Split function

    On Oct 24, 5:15 pm, "IT Staff" <jkk...@xxxxxx> wrote:

    > $sam = "ntid"
    > $searcher=New-Object DirectoryServices.DirectorySearcher
    > $searcher.Filter="(&(objectcategory=person)(objectclass=user)(samaccountname="+$sam+"))"
    > $results=$searcher.FindOne()
    > Write-Host $results.properties.homemdb
    >
    > The homemdb properties shows
    >
    > CN=607MB-SG2-MBS2-Std,CN=607MB-SG2,CN=InformationStore,CN=D1SNX607MB,CN=Servers,
    > CN=Second Administrative Group,CN=Administrative
    > Groups,CN=NOL-APL,CN=Microsoft
    >
    > I split by doing the following :
    >
    > $a = $results.properties.homemdb
    > $b = $a.split(",")
    >
    > But it does not work, why ?
    >
    > "IT Staff" <jkk...@xxxxxx> wrote in message
    >
    > news:eIT%236NiFIHA.3548@xxxxxx
    >

    > > How do i call from .net ?
    I am not familiar with the SearchResult class that you get as a return
    value from the DirectoryServices.DirectorySearcher.FindOne() method,
    so I just have to guess here, based on cursory perusal of MSDN
    documentation. Properties refers to a ResultPropertyCollection, and
    I'm guessing the following two statements are equivalent:

    $results.properties.homemdb

    $results.properties.item( "homedb" )

    PowerShell allows the first syntax with hashtables, so I assume the
    same this is happening with the Dictionary used in the
    ResultPropertyCollection. It looks like the Item method returns a
    string, so it seems to me that what you are trying to do should work.
    You might want to double check that you are dealing with a string:

    $results.properties.homemdb | Get-Member

    if the TypeName is not System.String, that will explain your
    problems. If it is, and if it still isn't splitting on the comma,
    please post exactly what you _are_ getting with your call to Split().
    Is it an error message, or just not what you expect?

    Jeff


      My System SpecsSystem Spec

  6. #6


    Brandon Shell [MVP] Guest

    Re: Split function

    Try

    $a = $results.properties.homemdb[0]
    $b = $a.Split(",")

    The problem is that you getting back a properties set result and the string
    in the value.


    Hello IT,

    > $sam = "ntid"
    > $searcher=New-Object DirectoryServices.DirectorySearcher
    > $searcher.Filter="(&(objectcategory=person)(objectclass=user)(samaccou
    > ntname="+$sam+"))"
    > $results=$searcher.FindOne()
    > Write-Host $results.properties.homemdb
    > The homemdb properties shows
    >
    > CN=607MB-SG2-MBS2-Std,CN=607MB-SG2,CN=InformationStore,CN=D1SNX607MB,C
    > N=Servers,
    > CN=Second Administrative Group,CN=Administrative
    > Groups,CN=NOL-APL,CN=Microsoft
    > I split by doing the following :
    >
    > $a = $results.properties.homemdb
    > $b = $a.split(",")
    > But it does not work, why ?
    >
    > "IT Staff" <jkklim@xxxxxx> wrote in message
    > news:eIT%236NiFIHA.3548@xxxxxx
    >

    >> How do i call from .net ?
    >>


      My System SpecsSystem Spec

  7. #7


    Hal Rottenberg Guest

    Re: Split function

    IT Staff wrote:

    > think i manage to do it by doing the following :
    >
    > $a = [string] $results.properties.homemdb
    > $b = $a.split(",")
    >
    > write-host $b[0] #to get the element i need
    Also note that many objects have a ToString method. It could be as easy as
    $a.tostring.split() or $a.propertyname.tostring.split(). Use Get-Member to find
    out.

    --

    Hal Rottenberg
    blog: http://halr9000.com
    powershell category:
    http://halr9000.com/article/category...ng/powershell/

      My System SpecsSystem Spec

Split function problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function... popular topic today! Dan VB Script 7 23 Mar 2010
VBscript Array Split Function turtle VB Script 9 03 Apr 2009
Problem using split function Meat VB Script 2 23 Jul 2008
Perl split function equivalent Frank PowerShell 3 14 Feb 2007
BUG: Redirecting function contents to a file truncates function lines at the width of the console Adam Milazzo PowerShell 2 11 Aug 2006