簡體   English   中英

PowerShell將集合移動到SCCM中的另一個文件夾?

[英]PowerShell Move collection to another folder in SCCM?

我有一個在SCCM中創建集合的腳本,但是我需要在“設備集合”下的一個子文件夾中創建它。 我看不出如何使用WMI類移動集合。 由於此腳本未在SCCM服務器本身上運行,因此我無法將configmanager模塊用於Move-CMobject 有沒有一種使用下面的PowerShell代碼樣式來實現集合移動的方法?

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

你需要的方法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,因為它將位於根目錄中。 對於現有文件夾,您可以用與目標文件夾相同的方法來計算。

我發現的一些代碼示例中也有此列表,該列表沒有源,但可能是正確的。

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實例,然后僅檢查給定文件夾的類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM