简体   繁体   English

Powershell SCCM 2012移动驱动程序包

[英]Powershell SCCM 2012 Moving Driver Package

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. 所以我有这个可爱的脚本,它将在SCCM 2012中制作文件夹和驱动程序包,它创建了文件夹和驱动程序包,但是我不知道如何将它们放入正确的文件夹中。 I thought that PkgFlags would do it but that seems to do nothing and i can't find a function to move the package. 我以为PkgFlags可以做到,但那似乎什么也没做,而且我找不到移动包的函数。

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
            }
        }
    }
}

If you are talking about folder in SCCM itself, there is another wmi class you need called SMS_ObjectContainerItem. 如果您在谈论SCCM本身中的文件夹,则需要另一个名为SMS_ObjectContainerItem的wmi类。 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: 我实际上并没有在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()

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM