Unable to Select-Object


  1.    18 Jan 2008 #1
    Tom Moreau Guest

    Unable to Select-Object


    I am running the following code:


    [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
    $smo = new-object Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"} | Select-Object Indexes | foreach {Write-Host $_.name}

    The last statement writes an empty line for each table in the Tables
    collection. (I'm using Write-Host just for debugging. I actually want to
    manipulate each index.) When I run the following:

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"} | Select-Object Indexes

    .... I get the following output:

    Indexes
    -------
    {PK_ContactCreditCard_ContactID_CreditCardID}
    {IX_CountryRegionCurrency_CurrencyCode,
    PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    {AK_Currency_Name, PK_Currency_CurrencyCode}
    {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    PK_CurrencyRate_CurrencyRateID}
    ....


    How do I pick up the object within the foreach loop?
    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    SQL Server MVP
    Toronto, ON Canada
    https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  2.    18 Jan 2008 #2
    Brandon Shell [MVP] Guest

    Re: Unable to Select-Object


    It seems to me it is just an array so this should work

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq "Sales"}
    | Select-Object Indexes | foreach {Write-Host $_}

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> I am running the following code:
    TM>
    TM> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServe
    TM> r.Smo") $smo = new-object Microsoft.SqlServer.Management.Smo.Server
    TM> ".\SQL2005"
    TM>
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host $_.name}
    TM>
    TM> The last statement writes an empty line for each table in the Tables
    TM> collection. (I'm using Write-Host just for debugging. I actually
    TM> want to manipulate each index.) When I run the following:
    TM>
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq "Sales"} | Select-Object Indexes
    TM>
    TM> ... I get the following output:
    TM>
    TM> Indexes
    TM> -------
    TM> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM> {IX_CountryRegionCurrency_CurrencyCode,
    TM> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM> PK_CurrencyRate_CurrencyRateID}
    TM> ...
    TM> How do I pick up the object within the foreach loop?
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  3.    18 Jan 2008 #3
    Brandon Shell [MVP] Guest

    Re: Unable to Select-Object


    What do you get back when you do this.

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq "Sales"}|
    Select-Object Indexes

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> No, I get this back:
    TM>
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>
    TM> It really is supposed to be a collection of Index objects.
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM> It seems to me it is just an array so this should work
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq
    TM> "Sales"}
    TM> | Select-Object Indexes | foreach {Write-Host $_}
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> I am running the following code:
    TM>>
    TM>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServ
    TM>> e r.Smo") $smo = new-object
    TM>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host $_.name}
    TM>>
    TM>> The last statement writes an empty line for each table in the
    TM>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>> actually want to manipulate each index.) When I run the following:
    TM>>
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq "Sales"} | Select-Object Indexes
    TM>>
    TM>> ... I get the following output:
    TM>>
    TM>> Indexes
    TM>> -------
    TM>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>> PK_CurrencyRate_CurrencyRateID}
    TM>> ...
    TM>> How do I pick up the object within the foreach loop?
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  4.    18 Jan 2008 #4
    Tom Moreau Guest

    Re: Unable to Select-Object


    No, I get this back:

    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}

    It really is supposed to be a collection of Index objects.

    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    SQL Server MVP
    Toronto, ON Canada
    https://mvp.support.microsoft.com/profile/Tom.Moreau


    "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    news:29d4f646387e8ca27da71057e80@xxxxxx
    It seems to me it is just an array so this should work

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"}
    | Select-Object Indexes | foreach {Write-Host $_}

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> I am running the following code:
    TM>
    TM> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServe
    TM> r.Smo") $smo = new-object Microsoft.SqlServer.Management.Smo.Server
    TM> ".\SQL2005"
    TM>
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host $_.name}
    TM>
    TM> The last statement writes an empty line for each table in the Tables
    TM> collection. (I'm using Write-Host just for debugging. I actually
    TM> want to manipulate each index.) When I run the following:
    TM>
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq "Sales"} | Select-Object Indexes
    TM>
    TM> ... I get the following output:
    TM>
    TM> Indexes
    TM> -------
    TM> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM> {IX_CountryRegionCurrency_CurrencyCode,
    TM> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM> PK_CurrencyRate_CurrencyRateID}
    TM> ...
    TM> How do I pick up the object within the foreach loop?
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  5.    18 Jan 2008 #5
    Tom Moreau Guest

    Re: Unable to Select-Object


    That was in my original post:

    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq "Sales"} | Select-Object Indexes
    TM>>
    TM>> ... I get the following output:
    TM>>
    TM>> Indexes
    TM>> -------
    TM>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>> PK_CurrencyRate_CurrencyRateID}


    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    SQL Server MVP
    Toronto, ON Canada
    https://mvp.support.microsoft.com/profile/Tom.Moreau


    "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    news:29d4f64638818ca27dc0111014c@xxxxxx
    What do you get back when you do this.

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"}|
    Select-Object Indexes

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> No, I get this back:
    TM>
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>
    TM> It really is supposed to be a collection of Index objects.
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM> It seems to me it is just an array so this should work
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq
    TM> "Sales"}
    TM> | Select-Object Indexes | foreach {Write-Host $_}
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> I am running the following code:
    TM>>
    TM>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServ
    TM>> e r.Smo") $smo = new-object
    TM>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host $_.name}
    TM>>
    TM>> The last statement writes an empty line for each table in the
    TM>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>> actually want to manipulate each index.) When I run the following:
    TM>>
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq "Sales"} | Select-Object Indexes
    TM>>
    TM>> ... I get the following output:
    TM>>
    TM>> Indexes
    TM>> -------
    TM>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>> PK_CurrencyRate_CurrencyRateID}
    TM>> ...
    TM>> How do I pick up the object within the foreach loop?
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  6.    18 Jan 2008 #6
    Brandon Shell [MVP] Guest

    Re: Unable to Select-Object


    Ok.. I think the problem is that Indexes returns and array of These
    http://technet.microsoft.com/zh-cn/l...n_members.aspx
    which contain these
    http://technet.microsoft.com/zh-cn/l...smo.index.aspx

    While you could do this on oneline.. I think it is unreadable so I would
    do this ( sorry I cant test im doing this in head :S )

    $Indexes = $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    -eq "Sales"}| Select-Object Indexes
    foreach($Index in $Indexes)
    {
    $Index | %{$_.Name}
    }

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> That was in my original post:
    TM>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes
    TM>>>
    TM>>> ... I get the following output:
    TM>>>
    TM>>> Indexes
    TM>>> -------
    TM>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>>> PK_CurrencyRate_CurrencyRateID}
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM> news:29d4f64638818ca27dc0111014c@xxxxxx
    TM> What do you get back when you do this.
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq
    TM> "Sales"}|
    TM> Select-Object Indexes
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> No, I get this back:
    TM>>
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>
    TM>> It really is supposed to be a collection of Index objects.
    TM>>
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM>> It seems to me it is just an array so this should work
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq
    TM>> "Sales"}
    TM>> | Select-Object Indexes | foreach {Write-Host $_}
    TM>> Brandon Shell
    TM>> ---------------
    TM>> Blog: http://www.bsonposh.com/
    TM>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>> I am running the following code:
    TM>>>
    TM>>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlSer
    TM>>> v e r.Smo") $smo = new-object
    TM>>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host
    TM>>> $_.name}
    TM>>>
    TM>>> The last statement writes an empty line for each table in the
    TM>>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>>> actually want to manipulate each index.) When I run the
    TM>>> following:
    TM>>>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes
    TM>>>
    TM>>> ... I get the following output:
    TM>>>
    TM>>> Indexes
    TM>>> -------
    TM>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>>> PK_CurrencyRate_CurrencyRateID}
    TM>>> ...
    TM>>> How do I pick up the object within the foreach loop?
    TM>>> ----------------------------------------------------
    TM>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>> SQL Server MVP
    TM>>> Toronto, ON Canada
    TM>>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  7.    18 Jan 2008 #7
    Tom Moreau Guest

    Re: Unable to Select-Object


    I get nothing back from this. I still don't get why foreach just isn't
    getting the object.

    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    SQL Server MVP
    Toronto, ON Canada
    https://mvp.support.microsoft.com/profile/Tom.Moreau


    "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    news:29d4f646388c8ca27e0af10ce1d@xxxxxx
    Ok.. I think the problem is that Indexes returns and array of These
    http://technet.microsoft.com/zh-cn/l...n_members.aspx
    which contain these
    http://technet.microsoft.com/zh-cn/l...smo.index.aspx

    While you could do this on oneline.. I think it is unreadable so I would
    do this ( sorry I cant test im doing this in head :S )

    $Indexes = $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    -eq "Sales"}| Select-Object Indexes
    foreach($Index in $Indexes)
    {
    $Index | %{$_.Name}
    }

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> That was in my original post:
    TM>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes
    TM>>>
    TM>>> ... I get the following output:
    TM>>>
    TM>>> Indexes
    TM>>> -------
    TM>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>>> PK_CurrencyRate_CurrencyRateID}
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM> news:29d4f64638818ca27dc0111014c@xxxxxx
    TM> What do you get back when you do this.
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq
    TM> "Sales"}|
    TM> Select-Object Indexes
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> No, I get this back:
    TM>>
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>
    TM>> It really is supposed to be a collection of Index objects.
    TM>>
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM>> It seems to me it is just an array so this should work
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq
    TM>> "Sales"}
    TM>> | Select-Object Indexes | foreach {Write-Host $_}
    TM>> Brandon Shell
    TM>> ---------------
    TM>> Blog: http://www.bsonposh.com/
    TM>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>> I am running the following code:
    TM>>>
    TM>>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlSer
    TM>>> v e r.Smo") $smo = new-object
    TM>>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host
    TM>>> $_.name}
    TM>>>
    TM>>> The last statement writes an empty line for each table in the
    TM>>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>>> actually want to manipulate each index.) When I run the
    TM>>> following:
    TM>>>
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq "Sales"} | Select-Object Indexes
    TM>>>
    TM>>> ... I get the following output:
    TM>>>
    TM>>> Indexes
    TM>>> -------
    TM>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode,
    TM>>> PK_CurrencyRate_CurrencyRateID}
    TM>>> ...
    TM>>> How do I pick up the object within the foreach loop?
    TM>>> ----------------------------------------------------
    TM>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>> SQL Server MVP
    TM>>> Toronto, ON Canada
    TM>>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  8.    18 Jan 2008 #8
    Brandon Shell [MVP] Guest

    Re: Unable to Select-Object


    That is because Indexes is an array of arrays

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq "Sales"}|
    Select-Object Indexes | %{$_} | %{$_.name}

    Perhaps I can explain what I think is happening
    * Select-Object Indexes # this passes just the Collection of Index Collections
    down the pipe
    * | %{$_} # This takes each Index Collection and passes
    it down the pipe
    * | %{$_.name} # This should get each Index in the Index Collection
    and Ouput just the Name

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> I get nothing back from this. I still don't get why foreach just
    TM> isn't getting the object.
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>
    TM> news:29d4f646388c8ca27e0af10ce1d@xxxxxx
    TM>
    TM> Ok.. I think the problem is that Indexes returns and array of These
    TM>
    TM> http://technet.microsoft.com/zh-cn/l...qlserver.manag
    TM> ement.smo.indexcollection_members.aspx
    TM>
    TM> which contain these
    TM>
    TM> http://technet.microsoft.com/zh-cn/l...qlserver.manag
    TM> ement.smo.index.aspx
    TM>
    TM> While you could do this on oneline.. I think it is unreadable so I
    TM> would do this ( sorry I cant test im doing this in head :S )
    TM>
    TM> $Indexes = $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM> {$_.Schema
    TM> -eq "Sales"}| Select-Object Indexes
    TM> foreach($Index in $Indexes)
    TM> {
    TM> $Index | %{$_.Name}
    TM> }
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> That was in my original post:
    TM>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes
    TM>>>>
    TM>>>> ... I get the following output:
    TM>>>>
    TM>>>> Indexes
    TM>>>> -------
    TM>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode
    TM>>>> ,
    TM>>>> PK_CurrencyRate_CurrencyRateID}
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>> news:29d4f64638818ca27dc0111014c@xxxxxx
    TM>> What do you get back when you do this.
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq
    TM>> "Sales"}|
    TM>> Select-Object Indexes
    TM>> Brandon Shell
    TM>> ---------------
    TM>> Blog: http://www.bsonposh.com/
    TM>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>> No, I get this back:
    TM>>>
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>
    TM>>> It really is supposed to be a collection of Index objects.
    TM>>>
    TM>>> ----------------------------------------------------
    TM>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>> SQL Server MVP
    TM>>> Toronto, ON Canada
    TM>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>>> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM>>> It seems to me it is just an array so this should work
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq
    TM>>> "Sales"}
    TM>>> | Select-Object Indexes | foreach {Write-Host $_}
    TM>>> Brandon Shell
    TM>>> ---------------
    TM>>> Blog: http://www.bsonposh.com/
    TM>>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>>> I am running the following code:
    TM>>>>
    TM>>>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlSe
    TM>>>> r v e r.Smo") $smo = new-object
    TM>>>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host
    TM>>>> $_.name}
    TM>>>>
    TM>>>> The last statement writes an empty line for each table in the
    TM>>>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>>>> actually want to manipulate each index.) When I run the
    TM>>>> following:
    TM>>>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes
    TM>>>>
    TM>>>> ... I get the following output:
    TM>>>>
    TM>>>> Indexes
    TM>>>> -------
    TM>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode
    TM>>>> ,
    TM>>>> PK_CurrencyRate_CurrencyRateID}
    TM>>>> ...
    TM>>>> How do I pick up the object within the foreach loop?
    TM>>>> ----------------------------------------------------
    TM>>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>>> SQL Server MVP
    TM>>>> Toronto, ON Canada
    TM>>>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  9.    18 Jan 2008 #9
    Tom Moreau Guest

    Re: Unable to Select-Object


    I got nothing back from that, too. I have made some progress, though.
    Here' what I have so far:

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"} | foreach {$Table = $_.Name; Write-Host $Table; foreach ($Index in
    $_.Indexes) {Write-host "`t" $Index.Name "`t" $Index.SpaceUsed}}

    When I add other methods in the second foreach, I'm not seeing evidence that
    they were actually sent to SQL Server, but that may be more of a SMO issue
    than PowerShell.

    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    SQL Server MVP
    Toronto, ON Canada
    https://mvp.support.microsoft.com/profile/Tom.Moreau


    "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    news:29d4f64638948ca27e45cab9041@xxxxxx
    That is because Indexes is an array of arrays

    $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema -eq
    "Sales"}|
    Select-Object Indexes | %{$_} | %{$_.name}

    Perhaps I can explain what I think is happening
    * Select-Object Indexes # this passes just the Collection of Index
    Collections
    down the pipe
    * | %{$_} # This takes each Index Collection and passes
    it down the pipe
    * | %{$_.name} # This should get each Index in the Index
    Collection
    and Ouput just the Name

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> I get nothing back from this. I still don't get why foreach just
    TM> isn't getting the object.
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>
    TM> news:29d4f646388c8ca27e0af10ce1d@xxxxxx
    TM>
    TM> Ok.. I think the problem is that Indexes returns and array of These
    TM>
    TM> http://technet.microsoft.com/zh-cn/l...qlserver.manag
    TM> ement.smo.indexcollection_members.aspx
    TM>
    TM> which contain these
    TM>
    TM> http://technet.microsoft.com/zh-cn/l...qlserver.manag
    TM> ement.smo.index.aspx
    TM>
    TM> While you could do this on oneline.. I think it is unreadable so I
    TM> would do this ( sorry I cant test im doing this in head :S )
    TM>
    TM> $Indexes = $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM> {$_.Schema
    TM> -eq "Sales"}| Select-Object Indexes
    TM> foreach($Index in $Indexes)
    TM> {
    TM> $Index | %{$_.Name}
    TM> }
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> That was in my original post:
    TM>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes
    TM>>>>
    TM>>>> ... I get the following output:
    TM>>>>
    TM>>>> Indexes
    TM>>>> -------
    TM>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode
    TM>>>> ,
    TM>>>> PK_CurrencyRate_CurrencyRateID}
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>> news:29d4f64638818ca27dc0111014c@xxxxxx
    TM>> What do you get back when you do this.
    TM>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>> -eq
    TM>> "Sales"}|
    TM>> Select-Object Indexes
    TM>> Brandon Shell
    TM>> ---------------
    TM>> Blog: http://www.bsonposh.com/
    TM>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>> No, I get this back:
    TM>>>
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>
    TM>>> It really is supposed to be a collection of Index objects.
    TM>>>
    TM>>> ----------------------------------------------------
    TM>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>> SQL Server MVP
    TM>>> Toronto, ON Canada
    TM>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>>> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM>>> It seems to me it is just an array so this should work
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq
    TM>>> "Sales"}
    TM>>> | Select-Object Indexes | foreach {Write-Host $_}
    TM>>> Brandon Shell
    TM>>> ---------------
    TM>>> Blog: http://www.bsonposh.com/
    TM>>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>>> I am running the following code:
    TM>>>>
    TM>>>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlSe
    TM>>>> r v e r.Smo") $smo = new-object
    TM>>>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes | foreach {Write-Host
    TM>>>> $_.name}
    TM>>>>
    TM>>>> The last statement writes an empty line for each table in the
    TM>>>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>>>> actually want to manipulate each index.) When I run the
    TM>>>> following:
    TM>>>>
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq "Sales"} | Select-Object Indexes
    TM>>>>
    TM>>>> ... I get the following output:
    TM>>>>
    TM>>>> Indexes
    TM>>>> -------
    TM>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode
    TM>>>> ,
    TM>>>> PK_CurrencyRate_CurrencyRateID}
    TM>>>> ...
    TM>>>> How do I pick up the object within the foreach loop?
    TM>>>> ----------------------------------------------------
    TM>>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>>> SQL Server MVP
    TM>>>> Toronto, ON Canada
    TM>>>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

  10.    18 Jan 2008 #10
    Brandon Shell [MVP] Guest

    Re: Unable to Select-Object


    I wish I could have been more help :S Glad you got it working


    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    TM> I got nothing back from that, too. I have made some progress,
    TM> though. Here' what I have so far:
    TM>
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq "Sales"} | foreach {$Table = $_.Name; Write-Host $Table; foreach
    TM> ($Index in $_.Indexes) {Write-host "`t" $Index.Name "`t"
    TM> $Index.SpaceUsed}}
    TM>
    TM> When I add other methods in the second foreach, I'm not seeing
    TM> evidence that they were actually sent to SQL Server, but that may be
    TM> more of a SMO issue than PowerShell.
    TM>
    TM> ----------------------------------------------------
    TM> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM> SQL Server MVP
    TM> Toronto, ON Canada
    TM> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM> news:29d4f64638948ca27e45cab9041@xxxxxx
    TM> That is because Indexes is an array of arrays
    TM> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM> -eq
    TM> "Sales"}|
    TM> Select-Object Indexes | %{$_} | %{$_.name}
    TM> Perhaps I can explain what I think is happening
    TM> * Select-Object Indexes # this passes just the Collection of Index
    TM> Collections
    TM> down the pipe
    TM> * | %{$_} # This takes each Index Collection and
    TM> passes
    TM> it down the pipe
    TM> * | %{$_.name} # This should get each Index in the Index
    TM> Collection
    TM> and Ouput just the Name
    TM> Brandon Shell
    TM> ---------------
    TM> Blog: http://www.bsonposh.com/
    TM> PSH Scripts Project: www.codeplex.com/psobject
    TM>> I get nothing back from this. I still don't get why foreach just
    TM>> isn't getting the object.
    TM>>
    TM>> ----------------------------------------------------
    TM>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>> SQL Server MVP
    TM>> Toronto, ON Canada
    TM>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>> news:29d4f646388c8ca27e0af10ce1d@xxxxxx
    TM>>
    TM>> Ok.. I think the problem is that Indexes returns and array of These
    TM>>
    TM>> http://technet.microsoft.com/zh-cn/l...sqlserver.mana
    TM>> g ement.smo.indexcollection_members.aspx
    TM>>
    TM>> which contain these
    TM>>
    TM>> http://technet.microsoft.com/zh-cn/l...sqlserver.mana
    TM>> g ement.smo.index.aspx
    TM>>
    TM>> While you could do this on oneline.. I think it is unreadable so I
    TM>> would do this ( sorry I cant test im doing this in head :S )
    TM>>
    TM>> $Indexes = $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM>> {$_.Schema
    TM>> -eq "Sales"}| Select-Object Indexes
    TM>> foreach($Index in $Indexes)
    TM>> {
    TM>> $Index | %{$_.Name}
    TM>> }
    TM>> Brandon Shell
    TM>> ---------------
    TM>> Blog: http://www.bsonposh.com/
    TM>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>> That was in my original post:
    TM>>>
    TM>>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM>>>>> {$_.Schema -eq "Sales"} | Select-Object Indexes
    TM>>>>>
    TM>>>>> ... I get the following output:
    TM>>>>>
    TM>>>>> Indexes
    TM>>>>> -------
    TM>>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCod
    TM>>>>> e
    TM>>>>> ,
    TM>>>>> PK_CurrencyRate_CurrencyRateID}
    TM>>> ----------------------------------------------------
    TM>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>> SQL Server MVP
    TM>>> Toronto, ON Canada
    TM>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
    TM>>> news:29d4f64638818ca27dc0111014c@xxxxxx
    TM>>> What do you get back when you do this.
    TM>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>> -eq
    TM>>> "Sales"}|
    TM>>> Select-Object Indexes
    TM>>> Brandon Shell
    TM>>> ---------------
    TM>>> Blog: http://www.bsonposh.com/
    TM>>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>>> No, I get this back:
    TM>>>>
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>> @{Indexes=Microsoft.SqlServer.Management.Smo.IndexCollection}
    TM>>>>
    TM>>>> It really is supposed to be a collection of Index objects.
    TM>>>>
    TM>>>> ----------------------------------------------------
    TM>>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>>> SQL Server MVP
    TM>>>> Toronto, ON Canada
    TM>>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
    TM>>>> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in
    TM>>>> message
    TM>>>> news:29d4f646387e8ca27da71057e80@xxxxxx
    TM>>>> It seems to me it is just an array so this should work
    TM>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object {$_.Schema
    TM>>>> -eq
    TM>>>> "Sales"}
    TM>>>> | Select-Object Indexes | foreach {Write-Host $_}
    TM>>>> Brandon Shell
    TM>>>> ---------------
    TM>>>> Blog: http://www.bsonposh.com/
    TM>>>> PSH Scripts Project: www.codeplex.com/psobject
    TM>>>>> I am running the following code:
    TM>>>>>
    TM>>>>> [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlS
    TM>>>>> e r v e r.Smo") $smo = new-object
    TM>>>>> Microsoft.SqlServer.Management.Smo.Server ".\SQL2005"
    TM>>>>>
    TM>>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM>>>>> {$_.Schema -eq "Sales"} | Select-Object Indexes | foreach
    TM>>>>> {Write-Host $_.name}
    TM>>>>>
    TM>>>>> The last statement writes an empty line for each table in the
    TM>>>>> Tables collection. (I'm using Write-Host just for debugging. I
    TM>>>>> actually want to manipulate each index.) When I run the
    TM>>>>> following:
    TM>>>>>
    TM>>>>> $smo.Databases["AdventureWorks"].Tables | Where-Object
    TM>>>>> {$_.Schema -eq "Sales"} | Select-Object Indexes
    TM>>>>>
    TM>>>>> ... I get the following output:
    TM>>>>>
    TM>>>>> Indexes
    TM>>>>> -------
    TM>>>>> {PK_ContactCreditCard_ContactID_CreditCardID}
    TM>>>>> {IX_CountryRegionCurrency_CurrencyCode,
    TM>>>>> PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode}
    TM>>>>> {AK_CreditCard_CardNumber, PK_CreditCard_CreditCardID}
    TM>>>>> {AK_Currency_Name, PK_Currency_CurrencyCode}
    TM>>>>> {AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCod
    TM>>>>> e
    TM>>>>> ,
    TM>>>>> PK_CurrencyRate_CurrencyRateID}
    TM>>>>> ...
    TM>>>>> How do I pick up the object within the foreach loop?
    TM>>>>> ----------------------------------------------------
    TM>>>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
    TM>>>>> SQL Server MVP
    TM>>>>> Toronto, ON Canada
    TM>>>>> https://mvp.support.microsoft.com/profile/Tom.Moreau


      My System SpecsSystem Spec

Page 1 of 3 123 LastLast
Unable to Select-Object

Similar Threads
Thread Forum
Select-Object *
Finally from the hints in this article http://app.en25.com/e/es.aspx?s=1403&e=753&elq=6a3dfdd2d44e43c184f27ab4d4958ead I have found a simple way to...
PowerShell
Select object with escaped wildcard
Hello there, I'm confused about how things work in this example: New-Object psobject| Add-Member noteproperty '*' 'a' -pass | select - expand...
PowerShell
select-object bug?
This came up on another post on this NG and for the benefit of all of us it deserves an explanation. dir -r | select -first 10 The first 10...
PowerShell
Select-Object in PS1 Script Bug?!
Hello, i have the PowerShell V2 (CTP) and have createt a ps1 script with more Select-Object commands. The first command with Select-Object is...
PowerShell
Select Multi Object in (my) computer
hi my name is mohammad and i'm software engineer. i install windows vista and i can't select multi objects in (my) computer. i try any way to do...
Vista General
Select a random object from pipeline effectively
Problem: Select a random object from the input pipeline without knowing the number of objects and without collecting the entire input. Remark:...
PowerShell
Select object as
How can you do a select object as specify the name of the property of the resultant object.. i.e gps | select-object name what if i want to...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 02:19.
    .