Question

so i have this lovely script that will make folders and driver packs in SCCM 2012, it created the folder and driver packages, but i can't work out how to put them in the correct folders. I thought that PkgFlags would do it but that seems to do nothing and i can't find a function to move the package.

i have worked on this for several days and have gotten nowhere

please help

$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
            }
        }
    }
}
Was it helpful?

Solution

If you are talking about folder in SCCM itself, there is another wmi class you need called SMS_ObjectContainerItem. It basically tells the driver which folder to go in.

I haven't actually scripted it in 2012, but in a script I wrote that creates advertisements, I had code that looked like this:

#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()

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top