0

所以我有这个可爱的脚本,它将在 SCCM 2012 中创建文件夹和驱动程序包,它创建了文件夹和驱动程序包,但我不知道如何将它们放在正确的文件夹中。我认为 PkgFlags 会这样做,但这似乎什么也没做,我找不到移动包的函数。

我已经为此工作了几天,但一无所获

请帮忙

$SCCMSiteCode = Read-Host "SCCM Site Code"
$PackageNamePath = Read-Host "Driver Package Original Path"
$PackageSourcePath = Read-Host "Driver Package Source Path"
$FolderArray1 = Get-ChildItem -Path "$PackageNamePath"

foreach ($FolderList1 in $FolderArray1)
{
if (($FolderList1.name -Like "Server*") -or ($FolderList1.name -Like "Windows*"))
    {
    $Argument1 = @{Name = "$FolderList1"; ObjectType = 23; ParentContainerNodeId = 0}
    Set-WmiInstance -Namespace "root\sms\site_$SCCMSiteCode" -Class "SMS_ObjectContainerNode" -Arguments $Argument1
    $GetID1 = Get-wmiObject -Namespace root\SMS\site_$SCCMSiteCode -Query "Select name,containernodeid from SMS_ObjectContainerNode" | select name,ContainerNodeID | Where-Object {$_.Name -eq $FolderList1}
    $FolderArray2 = Get-ChildItem -Path "$PackageNamePath\$FolderList1"
    foreach ($FolderList2 in $FolderArray2)
        {
        if (($FolderList2.name -NotLike "Server*") -or ($FolderList2.name -NotLike "Windows*"))
            {
            $DateTime = get-date -Format yyyy.MM.dd-hh.mm.ss
            $Milliseconds = (get-date).millisecond
            $FullDateTime = "$DateTime.$Milliseconds"
            New-Item -ItemType Directory -Path "$PackageSourcePath\$FullDateTime" 
            $PackageName = "$FolderList2 - $FolderList1"
            $Argument2 = @{Name = "$PackageName"; PkgSourcePath = "$PackageSourcePath\$FullDateTime"; PkgSourceFlag = 2; PkgFlags = $GetID1.ContainerNodeID}
            Set-WmiInstance -Namespace "root\sms\site_$SCCMSiteCode" -Class "SMS_DriverPackage" -Arguments $Argument2
            }
        }
    }
}
4

1 回答 1

1

如果您在谈论 SCCM 本身中的文件夹,则需要另一个名为 SMS_ObjectContainerItem 的 wmi 类。它基本上告诉驱动程序进入哪个文件夹。

我实际上在 2012 年还没有编写脚本,但是在我编写的创建广告的脚本中,我的代码如下所示:

#This gets the folder from wmi. $advContName is the name of the folder I want the ADV to end up in
$advContainer = gwmi -name root\sms\site_ia1 -computer itsnt353 -query "Select * from SMS_ObjectContainerNode WHERE Name='$advContName' AND ObjectType='3'"

$moveADV = ([WMIClass]\\itsnt353\root\sms\site_ia1:SMS_ObjectContainerItem").CreateInstance()
$moveADV.InstanceKey = $advID
$moveADV.ObjectType = 2;
$moveADV.ContainerNodeID = $advContainer.ContainerNodeID
$moveADV.Put()

我希望这有帮助。

于 2012-12-05T20:03:39.797 回答