![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
| | #5 (permalink) |
| 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 Specs![]() |
| | #6 (permalink) |
| 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 Specs![]() |
| | #7 (permalink) |
| 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 Specs![]() |
| | #8 (permalink) |
| 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 Specs![]() |
| | #9 (permalink) |
| 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 Specs![]() |
| | #10 (permalink) |
| 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 Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| select-object bug? | Shay Levi | PowerShell | 9 | 04-08-2008 03:51 PM |
| select-object not returning properties that are objects | Jason | PowerShell | 5 | 02-04-2008 09:01 AM |
| Select-Object in PS1 Script Bug?! | ||||