SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


get-unique


get-unique

Author
Message
schleep
schleep
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2843 Visits: 1406
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





jjtetzlo
jjtetzlo
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1752 Visits: 5038
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
schleep
schleep
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2843 Visits: 1406
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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search