Powershell SCCM 2012移动驱动程序包

时间:2012-11-14 12:11:17

标签: powershell wmi sccm

所以我有这个可爱的脚本,它将在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
            }
        }
    }
}

1 个答案:

答案 0 :(得分: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()

我希望这会有所帮助。