Advertisement
easternnl

SCCM - Operational Collections

Dec 3rd, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #############################################################################
  2. # Author  : Benoit Lecours
  3. # Website : www.SystemCenterDudes.com
  4. # Twitter : @scdudes
  5. #
  6. # Version : 1.0
  7. # Created : 2014/07/17
  8. # Modified :
  9. # 2014/08/14 - Added Collection 34,35,36
  10. # 2014/09/23 - Changed collection 4 to CU3 instead of CU2
  11. # 2015/01/30 - Improve Android collection
  12. # 2015/02/03 - Changed collection 4 to CU4 instead of CU3
  13. # 2015/05/06 - Changed collection 4 to CU5 instead of CU4
  14. # 2015/05/06 - Changed collection 4 to SP1 instead of CU5
  15. #            - Add collections 37 to 42
  16. #
  17. # Purpose : This script create a set of SCCM collections and move it in an "Operational" folder
  18. #
  19. #############################################################################
  20.  
  21. #Load Configuration Manager PowerShell Module
  22. Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
  23.  
  24. #Get SiteCode
  25. $SiteCode = Get-PSDrive -PSProvider CMSITE
  26. Set-location $SiteCode":"
  27.  
  28. #Refresh Schedule
  29. $Schedule = New-CMSchedule –RecurInterval Days –RecurCount 7
  30.  
  31. #List of Collections Query
  32. $Collection1 = @{Name = "All Clients"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.Client = 1"}
  33. $Collection2 = @{Name = "All Clients Inactive"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_CH_ClientSummary on SMS_G_System_CH_ClientSummary.ResourceId = SMS_R_System.ResourceId where SMS_G_System_CH_ClientSummary.ClientActiveStatus = 0 and SMS_R_System.Client = 1 and SMS_R_System.Obsolete = 0"}
  34. $Collection3 = @{Name = "All Clients Active"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_CH_ClientSummary on SMS_G_System_CH_ClientSummary.ResourceId = SMS_R_System.ResourceId where SMS_G_System_CH_ClientSummary.ClientActiveStatus = 1 and SMS_R_System.Client = 1 and SMS_R_System.Obsolete = 0"}
  35. $Collection4 = @{Name = "All Clients Non R2 SP1"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion != '5.00.8239.1000'"}
  36. $Collection5 = @{Name = "All Clients Not Reporting HW since 14 days"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where ResourceId in (select SMS_R_System.ResourceID from SMS_R_System inner join SMS_G_System_WORKSTATION_STATUS on SMS_G_System_WORKSTATION_STATUS.ResourceID = SMS_R_System.ResourceId where DATEDIFF(dd,SMS_G_System_WORKSTATION_STATUS.LastHardwareScan,GetDate()) > 14)"}
  37. $Collection6 = @{Name = "All Systems Non Client"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.Client = 0 OR SMS_R_System.Client is NULL"}
  38. $Collection7 = @{Name = "All Systems Obsolete"; Query = "select *  from  SMS_R_System where SMS_R_System.Obsolete = 1"}
  39. $Collection8 = @{Name = "All Workstations Active"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_CH_ClientSummary on SMS_G_System_CH_ClientSummary.ResourceId = SMS_R_System.ResourceId where (SMS_R_System.OperatingSystemNameandVersion like 'Microsoft Windows NT%Workstation%' or SMS_R_System.OperatingSystemNameandVersion = 'Windows 7 Entreprise 6.1') and SMS_G_System_CH_ClientSummary.ClientActiveStatus = 1 and SMS_R_System.Client = 1 and SMS_R_System.Obsolete = 0"}
  40. $Collection9 = @{Name = "All Laptops"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes in ('8', '9', '10', '11', '12', '14', '18', '21')"}
  41. $Collection10 = @{Name = "All Servers"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where OperatingSystemNameandVersion like '%Server%'"}
  42. $Collection11 = @{Name = "All Servers Physical"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId not in (select SMS_R_SYSTEM.ResourceID from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.IsVirtualMachine = 'True') and SMS_R_System.OperatingSystemNameandVersion like 'Microsoft Windows NT%Server%'"}
  43. $Collection12 = @{Name = "All Servers Virtual"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.IsVirtualMachine = 'True' and SMS_R_System.OperatingSystemNameandVersion like 'Microsoft Windows NT%Server%'"}
  44. $Collection13 = @{Name = "All Workstations"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where OperatingSystemNameandVersion like '%Workstation%'"}
  45. $Collection14 = @{Name = "All Windows 7 Workstations"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Workstation 6.1%'"}
  46. $Collection15 = @{Name = "All Windows 8 Workstations"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Workstation 6.2%'"}
  47. $Collection16 = @{Name = "All Windows 8.1 Workstations"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Workstation 6.3%'"}
  48. $Collection17 = @{Name = "All Windows XP Workstation"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System   where OperatingSystemNameandVersion like '%Workstation 5.1%' or OperatingSystemNameandVersion like '%Workstation 5.2%'"}
  49. $Collection18 = @{Name = "All Windows 2008 and 2008 R2"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Server 6.0%' or OperatingSystemNameandVersion like '%Server 6.1%'"}
  50. $Collection19 = @{Name = "All Windows 2012 and 2012 R2"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Server 6.2%' or OperatingSystemNameandVersion like '%Server 6.3%'"}
  51. $Collection20 = @{Name = "All Windows 2003 and 2003 R2"; Query = "select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where OperatingSystemNameandVersion like '%Server 5.2%'"}
  52. $Collection21 = @{Name = "All Systems Created Since 24h"; Query = "select SMS_R_System.Name, SMS_R_System.CreationDate FROM SMS_R_System WHERE DateDiff(dd,SMS_R_System.CreationDate, GetDate()) <= 1"}
  53. $Collection22 = @{Name = "All Systems with SCCM Console"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = 'System Center 2012 R2 Configuration Manager Console'"}
  54. $Collection23 = @{Name = "All SCCM Site System"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System where SMS_R_System.SystemRoles = 'SMS Site System'"}
  55. $Collection24 = @{Name = "All SCCM Site Server"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System where SMS_R_System.SystemRoles = 'SMS Site Server'"}
  56. $Collection25 = @{Name = "All SCCM Distribution Points"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from  SMS_R_System where SMS_R_System.SystemRoles = 'SMS Distribution Point'"}
  57. $Collection26 = @{Name = "All Windows Update Agent Version Outdated - Win7 RTM and lower"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_WINDOWSUPDATEAGENTVERSION on SMS_G_System_WINDOWSUPDATEAGENTVERSION.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_WINDOWSUPDATEAGENTVERSION.Version < '7.6.7600.256' and SMS_G_System_OPERATING_SYSTEM.Version <= '6.1.7600'"}
  58. $Collection27 = @{Name = "All Windows Update Agent Version Outdated - Win7 SP1 and higher"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_WINDOWSUPDATEAGENTVERSION on SMS_G_System_WINDOWSUPDATEAGENTVERSION.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_WINDOWSUPDATEAGENTVERSION.Version < '7.6.7600.320' and SMS_G_System_OPERATING_SYSTEM.Version >= '6.1.7601'"}
  59. $Collection28 = @{Name = "Mobile Devices - All Android"; Query = "SELECT SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client FROM SMS_R_System INNER JOIN SMS_G_System_DEVICE_OSINFORMATION ON SMS_G_System_DEVICE_OSINFORMATION.ResourceID = SMS_R_System.ResourceId WHERE SMS_G_System_DEVICE_OSINFORMATION.Platform like 'Android%'"}
  60. $Collection29 = @{Name = "Mobile Devices - All Iphone"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_DEVICE_COMPUTERSYSTEM on SMS_G_System_DEVICE_COMPUTERSYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_DEVICE_COMPUTERSYSTEM.DeviceModel like '%Iphone%'"}
  61. $Collection30 = @{Name = "Mobile Devices - All Ipad"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_DEVICE_COMPUTERSYSTEM on SMS_G_System_DEVICE_COMPUTERSYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_DEVICE_COMPUTERSYSTEM.DeviceModel like '%Ipad%'"}
  62. $Collection31 = @{Name = "Mobile Devices - All Windows 8"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from SMS_R_System inner join SMS_G_System_DEVICE_OSINFORMATION on SMS_G_System_DEVICE_OSINFORMATION.ResourceID = SMS_R_System.ResourceId where SMS_G_System_DEVICE_OSINFORMATION.Platform like 'Windows Phone' and SMS_G_System_DEVICE_OSINFORMATION.Version like '8.0%'"}
  63. $Collection32 = @{Name = "Mobile Devices - All Windows 8.1"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from SMS_R_System inner join SMS_G_System_DEVICE_OSINFORMATION on SMS_G_System_DEVICE_OSINFORMATION.ResourceID = SMS_R_System.ResourceId where SMS_G_System_DEVICE_OSINFORMATION.Platform like 'Windows Phone' and SMS_G_System_DEVICE_OSINFORMATION.Version like '8.1%'"}
  64. $Collection33 = @{Name = "Mobile Devices - All Windows RT"; Query = "select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model like 'Surface%'"}
  65. $Collection34 = @{Name = "All Systems Disabled"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.UserAccountControl ='4098'"}
  66. $Collection35 = @{Name = "All Clients x86"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.SystemType = 'X86-based PC'"}
  67. $Collection36 = @{Name = "All Clients x64"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.SystemType = 'X64-based PC'"}
  68. $Collection37 = @{Name = "All Clients R2 CU1"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1203'"}
  69. $Collection38 = @{Name = "All Clients R2 CU2"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1303'"}
  70. $Collection39 = @{Name = "All Clients R2 CU3"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1401'"}
  71. $Collection40 = @{Name = "All Clients R2 CU4"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1501'"}
  72. $Collection41 = @{Name = "All Clients R2 CU5"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1604'"}
  73. $Collection42 = @{Name = "All Clients R2 CU0"; Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ClientVersion = '5.00.7958.1000'"}
  74.  
  75. #Create Defaut Folder
  76. $CollectionFolder = @{Name = "Operational"; ObjectType = 5000; ParentContainerNodeId = 0}
  77. Set-WmiInstance -Namespace "root\sms\site_$($SiteCode.Name)" -Class "SMS_ObjectContainerNode" -Arguments $CollectionFolder
  78.  
  79. #Create Default limiting collections
  80. $LimitingCollection = "All Systems"
  81.  
  82. #Create Collection
  83.  
  84. New-CMDeviceCollection -Name $Collection1.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  85. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection1.Name -QueryExpression $Collection1.Query -RuleName $Collection1.Name
  86.  
  87. New-CMDeviceCollection -Name $Collection2.Name -LimitingCollectionName $Collection1.Name -RefreshSchedule $Schedule -RefreshType 2
  88. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection2.Name -QueryExpression $Collection2.Query -RuleName $Collection2.Name
  89.  
  90. New-CMDeviceCollection -Name $Collection3.Name -LimitingCollectionName $Collection1.Name -RefreshSchedule $Schedule -RefreshType 2
  91. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection3.Name -QueryExpression $Collection3.Query -RuleName $Collection3.Name
  92.  
  93. New-CMDeviceCollection -Name $Collection4.Name -LimitingCollectionName $Collection1.Name -RefreshSchedule $Schedule -RefreshType 2
  94. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection4.Name -QueryExpression $Collection4.Query -RuleName $Collection4.Name
  95.  
  96. New-CMDeviceCollection -Name $Collection5.Name -LimitingCollectionName $Collection1.Name -RefreshSchedule $Schedule -RefreshType 2
  97. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection5.Name -QueryExpression $Collection5.Query -RuleName $Collection5.Name
  98.  
  99. New-CMDeviceCollection -Name $Collection6.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  100. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection6.Name -QueryExpression $Collection6.Query -RuleName $Collection6.Name
  101.  
  102. New-CMDeviceCollection -Name $Collection7.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  103. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection7.Name -QueryExpression $Collection7.Query -RuleName $Collection7.Name
  104.  
  105. New-CMDeviceCollection -Name $Collection8.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  106. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection8.Name -QueryExpression $Collection8.Query -RuleName $Collection8.Name
  107.  
  108. New-CMDeviceCollection -Name $Collection9.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  109. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection9.Name -QueryExpression $Collection9.Query -RuleName $Collection9.Name
  110.  
  111. New-CMDeviceCollection -Name $Collection10.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  112. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection10.Name -QueryExpression $Collection10.Query -RuleName $Collection10.Name
  113.  
  114. New-CMDeviceCollection -Name $Collection11.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  115. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection11.Name -QueryExpression $Collection11.Query -RuleName $Collection11.Name
  116.  
  117. New-CMDeviceCollection -Name $Collection12.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  118. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection12.Name -QueryExpression $Collection12.Query -RuleName $Collection12.Name
  119.  
  120. New-CMDeviceCollection -Name $Collection13.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  121. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection13.Name -QueryExpression $Collection13.Query -RuleName $Collection13.Name
  122.  
  123. New-CMDeviceCollection -Name $Collection14.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  124. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection14.Name -QueryExpression $Collection14.Query -RuleName $Collection14.Name
  125.  
  126. New-CMDeviceCollection -Name $Collection15.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  127. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection15.Name -QueryExpression $Collection15.Query -RuleName $Collection15.Name
  128.  
  129. New-CMDeviceCollection -Name $Collection16.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  130. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection16.Name -QueryExpression $Collection16.Query -RuleName $Collection16.Name
  131.  
  132. New-CMDeviceCollection -Name $Collection17.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  133. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection17.Name -QueryExpression $Collection17.Query -RuleName $Collection17.Name
  134.  
  135. New-CMDeviceCollection -Name $Collection18.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  136. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection18.Name -QueryExpression $Collection18.Query -RuleName $Collection18.Name
  137.  
  138. New-CMDeviceCollection -Name $Collection19.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  139. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection19.Name -QueryExpression $Collection19.Query -RuleName $Collection19.Name
  140.  
  141. New-CMDeviceCollection -Name $Collection20.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  142. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection20.Name -QueryExpression $Collection20.Query -RuleName $Collection20.Name
  143.  
  144. New-CMDeviceCollection -Name $Collection21.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  145. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection21.Name -QueryExpression $Collection21.Query -RuleName $Collection21.Name
  146.  
  147. New-CMDeviceCollection -Name $Collection22.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  148. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection22.Name -QueryExpression $Collection22.Query -RuleName $Collection22.Name
  149.  
  150. New-CMDeviceCollection -Name $Collection23.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  151. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection23.Name -QueryExpression $Collection23.Query -RuleName $Collection23.Name
  152.  
  153. New-CMDeviceCollection -Name $Collection24.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  154. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection24.Name -QueryExpression $Collection24.Query -RuleName $Collection24.Name
  155.  
  156. New-CMDeviceCollection -Name $Collection25.Name -LimitingCollectionName $Collection10.Name -RefreshSchedule $Schedule -RefreshType 2
  157. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection25.Name -QueryExpression $Collection25.Query -RuleName $Collection25.Name
  158.  
  159. New-CMDeviceCollection -Name $Collection26.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  160. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection26.Name -QueryExpression $Collection26.Query -RuleName $Collection26.Name
  161.  
  162. New-CMDeviceCollection -Name $Collection27.Name -LimitingCollectionName $Collection13.Name -RefreshSchedule $Schedule -RefreshType 2
  163. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection27.Name -QueryExpression $Collection27.Query -RuleName $Collection27.Name
  164.  
  165. New-CMDeviceCollection -Name $Collection28.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  166. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection28.Name -QueryExpression $Collection28.Query -RuleName $Collection28.Name
  167.  
  168. New-CMDeviceCollection -Name $Collection29.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  169. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection29.Name -QueryExpression $Collection29.Query -RuleName $Collection29.Name
  170.  
  171. New-CMDeviceCollection -Name $Collection30.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  172. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection30.Name -QueryExpression $Collection30.Query -RuleName $Collection30.Name
  173.  
  174. New-CMDeviceCollection -Name $Collection31.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  175. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection31.Name -QueryExpression $Collection31.Query -RuleName $Collection31.Name
  176.  
  177. New-CMDeviceCollection -Name $Collection32.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  178. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection32.Name -QueryExpression $Collection32.Query -RuleName $Collection32.Name
  179.  
  180. New-CMDeviceCollection -Name $Collection33.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  181. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection33.Name -QueryExpression $Collection33.Query -RuleName $Collection33.Name
  182.  
  183. New-CMDeviceCollection -Name $Collection34.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  184. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection34.Name -QueryExpression $Collection34.Query -RuleName $Collection34.Name
  185.  
  186. New-CMDeviceCollection -Name $Collection35.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  187. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection35.Name -QueryExpression $Collection35.Query -RuleName $Collection35.Name
  188.  
  189. New-CMDeviceCollection -Name $Collection36.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  190. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection36.Name -QueryExpression $Collection36.Query -RuleName $Collection36.Name
  191.  
  192. New-CMDeviceCollection -Name $Collection37.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  193. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection37.Name -QueryExpression $Collection37.Query -RuleName $Collection37.Name
  194.  
  195. New-CMDeviceCollection -Name $Collection38.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  196. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection38.Name -QueryExpression $Collection38.Query -RuleName $Collection38.Name
  197.  
  198. New-CMDeviceCollection -Name $Collection39.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  199. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection39.Name -QueryExpression $Collection39.Query -RuleName $Collection39.Name
  200.  
  201. New-CMDeviceCollection -Name $Collection40.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  202. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection40.Name -QueryExpression $Collection40.Query -RuleName $Collection40.Name
  203.  
  204. New-CMDeviceCollection -Name $Collection41.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  205. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection41.Name -QueryExpression $Collection41.Query -RuleName $Collection41.Name
  206.  
  207. New-CMDeviceCollection -Name $Collection42.Name -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule -RefreshType 2
  208. Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection42.Name -QueryExpression $Collection42.Query -RuleName $Collection42.Name
  209.  
  210. #Move the collection to the right folder
  211. $FolderPath = $SiteCode.Name + ":\DeviceCollection\" + $CollectionFolder.Name
  212. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection1.Name)
  213. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection2.Name)
  214. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection3.Name)
  215. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection4.Name)
  216. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection5.Name)
  217. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection6.Name)
  218. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection7.Name)
  219. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection8.Name)
  220. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection9.Name)
  221. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection10.Name)
  222. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection11.Name)
  223. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection12.Name)
  224. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection13.Name)
  225. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection14.Name)
  226. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection15.Name)
  227. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection16.Name)
  228. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection17.Name)
  229. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection18.Name)
  230. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection19.Name)
  231. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection20.Name)
  232. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection21.Name)
  233. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection22.Name)
  234. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection23.Name)
  235. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection24.Name)
  236. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection25.Name)
  237. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection26.Name)
  238. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection27.Name)
  239. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection28.Name)
  240. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection29.Name)
  241. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection30.Name)
  242. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection31.Name)
  243. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection32.Name)
  244. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection33.Name)
  245. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection34.Name)
  246. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection35.Name)
  247. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection36.Name)
  248. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection37.Name)
  249. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection38.Name)
  250. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection39.Name)
  251. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection40.Name)
  252. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection41.Name)
  253. Move-CMObject -FolderPath $FolderPath -InputObject (Get-CMDeviceCollection -Name $Collection42.Name)
  254.  
  255.  
  256. Write-host "Completed !" -ForegroundColor WHITE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement