-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCCM - Collections by Hostname.ps1
51 lines (45 loc) · 1.96 KB
/
SCCM - Collections by Hostname.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.NOTES
===========================================================================
Created on: 2022-04-27
Created by: Brian Thorp
===========================================================================
.Description
Collection lookup with array filtering on output
#>
$SiteCode = "CCM" # Site code
$ProviderMachineName = "sccm.contoso.com" # SMS Provider machine name
# ======================================================================
# Code to get collections machine is a part of
# ======================================================================
$hostname = "DemoComputer"
$Collections = (Get-WmiObject -ComputerName $ProviderMachineName -Namespace "Root\SMS\Site_$SiteCode" -Query “SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where name = '$hostname' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID”)
$List = $($Collections.Name)
$Match1 = "Query"
$Match2 = "All"
$Match3 = "Department"
$Match4 = "matchtext4"
$Match5 = "matchtext5"
$Match6 = "matchtext6"
$Match7 = "matchtext7"
$Match8 = "matchtext8"
$Match9 = "matchtext9"
$Match10 = "matchtext10"
$OldContent = $List
$NewContent = $OldContent `
| Where-Object {$_ -notmatch $Match1} `
| Where-Object {$_ -notmatch $Match2} `
| Where-Object {$_ -notmatch $Match3} `
| Where-Object {$_ -notmatch $Match4} `
| Where-Object {$_ -notmatch $Match5} `
| Where-Object {$_ -notmatch $Match6} `
| Where-Object {$_ -notmatch $Match7} `
| Where-Object {$_ -notmatch $Match8} `
| Where-Object {$_ -notmatch $Match9} `
| Where-Object {$_ -notmatch $Match10}
$NewContent
# ======================================================================
# Make the above have an exclude or not
# ======================================================================
# Cast the collection array to an array list so we can add or remove from it
$NewContent = [System.Collections.ArrayList]$OldDeviceCollections