PowerShell将集合移动到SCCM中的另一个文件夹?

时间:2018-08-30 16:41:53

标签: powershell wmi sccm

我有一个脚本可以在SCCM中创建集合,但是我需要在“设备集合”下的一个子文件夹中创建它。我看不出如何使用WMI类移动集合。由于此脚本未在SCCM服务器本身上运行,因此我无法对Move-CMobject使用configmanager模块。是否可以使用下面的PowerShell代码样式来实现集合移动?

$CMCollection = ([WMIClass]”\root\sms\site_:SMS_Collection”).CreateInstance()
$CMCollection.name = $CollectionName
$CMCollection.LimitToCollectionID = “12345678”
$CMCollection.RefreshType = 2
$CMCollection.Put()

1 个答案:

答案 0 :(得分:1)

您需要类MoveMembers的方法SMS_ObjectContainerItem。创建集合后(无法在正确的路径中创建afaik)。

powershell代码如下:

[Array]$DeviceCollectionID = <CollID>
$TargetFolderID = <ContainerNodeID>
$CurrentFolderID = 0
$ObjectTypeID = 5000

Invoke-WmiMethod -Namespace 'Root\SMS\Site_<SiteCode>' -Class 'SMS_objectContainerItem' -Name 'MoveMembers' -ArgumentList $CurrentFolderID,$DeviceCollectionID,$ObjectTypeID,$TargetFolderID

要获取目标文件夹的ContainerNodeID,可以使用如下查询:

select * from sms_objectcontainernode where objecttypeName = 'sms_collection_device' where Name =<your target folder name>

我没有找到ObjectIDTypes的有效ms来源,但从我自己的程序和几个我知道5000的样本中可以找到集合文件夹。如果您刚刚以编程方式创建了某些内容,则CurrentFolderID始终为0,因为它将位于根目录中。对于现有文件夹,您可以通过与目标文件夹相同的方式来解决它。

我发现来自some code sample的这份清单也没有出处,但可能是正确的。

Object type 2 - Package Folder
Object type 7 - Query Folder
Object type 9 - Software Metering Folder
Object type 14 - Operating System Installers Folder
Object type 17 - State Migration GFolder
Object type 18 - Image Package Folder
Object type 19 - Boot Image Folder
Object type 20 - Task Sequence Folder
Object type 23 - Driver Package Folder
Object type 25 - Driver Folder
Object type 2011 - Configuration Baseline Folder
Object type 5000 - Device Collection Folder
Object type 5001 - User Collection Folder
Object type 6000 - Application Folder
Object type 6001 - Configuration Item Folder

如果您需要某种缺少的类型,您还可以查看sms_objectcontainernode实例,然后检查给定文件夹的类型