SCCM 2012 R2 - How do I find which collection a sever is in!

Hi there,

I wonder could someone help with me with something that is hopefully simple to do!

We have over 2000 servers in our SCCM 2012 R2 Config Manager Console and over 50 Device Collections so I wonder is there an easy way for me to search for a server by name and have SCCM tell me what collection or collections that servers is in?

The closest I get is by clicking on Devices and typing in the server name and it does show me the server I am after but I dont see any field/column that I can enable to show me what collection it is in.

So if anyone could point me in the right direction that would be great I presently I need to click through each collection to find where the servers are!

Thanks,

Bonemister
July 29th, 2015 11:38am

This is something i made for some one asked the same question as you:

Simple script i made a while back just save them as what ever you like and call the them using either the device name so it would go something like this  .\script.ps1 testserver


param (
[string]$device
)

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
$SiteServer = $SiteCode.Root  
set-location ($SiteCode.name+":")

$DID = (Get-CMDevice -Name $device).ResourceID
$Collections = (Get-WmiObject -Class sms_fullcollectionmembership -Namespace root\sms\site_$SiteCode -Filter "ResourceID = '$($DID)'").CollectionID
foreach ($Collection in $Collections)
        {
            Get-CMDeviceCollection -CollectionId $Collection | select Name, CollectionID
        }

https://social.technet.microsoft.com/Forums/en-US/41ab1e89-723c-44d7-8eed-072c8fd033df/report-or-query-to-see-which-collection-system-or-user-is-member-of?forum=configmanagergeneral



Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 11:41am

As a note here, this question is wrong. Collections in ConfigMgr do not represent a directory; a resource can be a member of many collections based upon the membership rules defined for the collections. Thus, there is no way to a add a field because it wouldn't make sense to do so as that field could contain any number of values so a single resource making it kind of useless (yes it could still be done as there are other multi-value fields but it doesn't add any true value).

You can use a report or query to do this as in the thread that Frederick linked to or the PowerShell script that he posted (which is really just a WMI Query).

July 29th, 2015 2:02pm

This is something i made for some one asked the same question as you:

Simple script i made a while back just save them as what ever you like and call the them using either the device name so it would go something like this  .\script.ps1 testserver


param (
[string]$device
)

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
$SiteServer = $SiteCode.Root  
set-location ($SiteCode.name+":")

$DID = (Get-CMDevice -Name $device).ResourceID
$Collections = (Get-WmiObject -Class sms_fullcollectionmembership -Namespace root\sms\site_$SiteCode -Filter "ResourceID = '$($DID)'").CollectionID
foreach ($Collection in $Collections)
        {
            Get-CMDeviceCollection -CollectionId $Collection | select Name, CollectionID
        }

https://social.technet.microsoft.com/Forums/en-US/41ab1e89-723c-44d7-8eed-072c8fd033df/report-or-query-to-see-which-collection-system-or-user-is-member-of?forum=configmanagergeneral



Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 3:40pm

This is something i made for some one asked the same question as you:

Simple script i made a while back just save them as what ever you like and call the them using either the device name so it would go something like this  .\script.ps1 testserver


param (
[string]$device
)

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
$SiteServer = $SiteCode.Root  
set-location ($SiteCode.name+":")

$DID = (Get-CMDevice -Name $device).ResourceID
$Collections = (Get-WmiObject -Class sms_fullcollectionmembership -Namespace root\sms\site_$SiteCode -Filter "ResourceID = '$($DID)'").CollectionID
foreach ($Collection in $Collections)
        {
            Get-CMDeviceCollection -CollectionId $Collection | select Name, CollectionID
        }

https://social.technet.microsoft.com/Forums/en-US/41ab1e89-723c-44d7-8eed-072c8fd033df/report-or-query-to-see-which-collection-system-or-user-is-member-of?forum=configmanagergeneral



July 29th, 2015 3:40pm

Hi Frederick,

Thank you very much for your scripts, they seem to be exactly what I am after.  I've tried to run the Device script with PowerShell as shown below but I get the following error and I can't understand what the problem is so any help would be greatly appreciated!

If I am supposed to enter the name of the device as a parameter somewhere please let me know where it needs to go?

Sorry, I am new to all of this stuff!

Thanks,

Bonemister

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> param (
>> [string]$device
>> )
>>
PS C:\Windows\system32> Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
PS C:\Windows\system32> $SiteCode = Get-PSDrive -PSProvider CMSITE
PS C:\Windows\system32> $SiteServer = $SiteCode.Root
PS C:\Windows\system32> set-location ($SiteCode.name+":")
PS WTR:\>
PS WTR:\> $DID = (Get-CMDevice -Name $device).ResourceID
Get-CMDevice : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that
is not null or empty, and then try the command again.
At line:1 char:28
+ $DID = (Get-CMDevice -Name $device).ResourceID
+                            ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-CMDevice], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ConfigurationManagement.Cmdlets.Collections.C
   ommands.GetDeviceCommand

PS WTR:\> $Collections = (Get-WmiObject -Class sms_fullcollectionmembership -Namespace root\sms\site_$SiteCode -Filter "
ResourceID = '$($DID)'").CollectionID
PS WTR:\> foreach ($Collection in $Collections)
>>         {
>>             Get-CMDeviceCollection -CollectionId $Collection | select Name, CollectionID
>>

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 9:51am

You need to call the script with the device name.

So if the script is call device.ps1 and the server you want to find it is call TESTSERVER you would do this from the sccm server powershell .

.\device.ps1 TESTSERVER

  • Marked as answer by bonemister 16 hours 39 minutes ago
July 30th, 2015 9:58am

Jason,

Sorry if I got my phrasing wrong, I am new to all of this and am still learning.

Could you please point me in the right direction as to which report or query I could use or how do I customise one to give me the info that I am after.

Thanks,

Bonemister

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 10:40am

Follow the link in the thread that Frederick linked to above.
July 30th, 2015 10:51am

Frederick,

Thanks a million, that worked a treat and is giving me exactly what I am after!

Our of curiosity what results does the 'User' script give/what is it user for and what is the syntax for running it?

Cheers for your help,

Bonemister

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 11:12am

Well the user script does the same thing as device except it look for users.

so you would run it the same way user.ps1 user  (look at the user collection to see the format of the users)

The code is here

param (
[string]$user
)

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
$SiteServer = $SiteCode.Root  
set-location ($SiteCode.name+":")

$UID = (Get-CMUser -Name $user).ResourceID
$Collections = (Get-WmiObject -Class sms_fullcollectionmembership -Namespace root\sms\site_$SiteCode -Filter "ResourceID = '$($UID)'").CollectionID
foreach ($Collection in $Collections)
        {
            Get-CMUserCollection -CollectionId $Collection | select Name, CollectionID
        }

July 30th, 2015 11:19am

You need to call the script with the device name.

So if the script is call device.ps1 and the server you want to find it is call TESTSERVER you would do this from the sccm server powershell .

.\device.ps1 TESTSERVER

  • Marked as answer by bonemister Thursday, July 30, 2015 3:12 PM
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 1:57pm

Hi Frederick,

Thanks for coming back to me again!

We don't have any users within our User Collections so I'll not worry to much about that users script but thank you so much for helping me out with this, it is much appreciated.

Kind regards,

Bonemister

July 31st, 2015 6:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics