Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

get-unique Expand / Collapse
Author
Message
Posted Wednesday, October 10, 2012 12:36 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 5:31 AM
Points: 433, Visits: 982
I want need to understand why the code below returns

alpha
-----
Y

Can someone explain why I don't see
alpha
-----
X
Y

Bonus points: if the last 2 lines are

$cAlphas = $Objects | select alpha | Get-Unique
$cAlphas

why do I get

alpha
-----
X


Thanks!

$Objects = @()

$Object = New-Object system.object
$Object | Add-Member -Type NoteProperty -Name alpha -value "X"
$Object | Add-Member -Type NoteProperty -Name Num -value "1"
$Objects += $Object

$Object = New-Object system.object
$Object | Add-Member -Type NoteProperty -Name alpha -value "X"
$Object | Add-Member -Type NoteProperty -Name Num -value "2"
$Objects += $Object

$Object = New-Object system.object
$Object | Add-Member -Type NoteProperty -Name alpha -value "Y"
$Object | Add-Member -Type NoteProperty -Name Num -value "1"
$Objects += $Object

$Object = New-Object system.object
$Object | Add-Member -Type NoteProperty -Name alpha -value "Y"
$Object | Add-Member -Type NoteProperty -Name Num -value "2"
$Objects += $Object

$cAlphas = $Objects | select alpha
$cAlphas | Sort-Object -Unique




Post #1371080
Posted Wednesday, October 10, 2012 2:46 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 8:02 AM
Points: 1,384, Visits: 4,820
This may not be a complete answer (I don't think I'll be getting any bonus points), but I was able to get the proper output by adding -Property to the Sort.

$cAlphas | Sort-Object -Property alpha -Unique


- Jeff
Post #1371122
Posted Thursday, October 11, 2012 7:56 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 5:31 AM
Points: 433, Visits: 982
SORRY: This should have been a new topic, reposting.

Hi,

I have 2 Array or ArrayList objects, with data like

$Results = New-Object system.Collections.ArrayList
$Results.Add("IMP_Trn_Project_Agent_6,User1")
$Results.Add("IMP_Trn_Project_Agent_6,User2")
$Results.Add("IMP_Trn_Project_Agent_6,User3")

$Remove = New-Object system.Collections.ArrayList
$Remove.Add("User2")


How can I efficiently remove from the first array all items containing the users in the 2nd array?

Paul



Post #1371504
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse