Dear colleagues,
I am currently struggling when trying to automate the creation of a SCCM Software Package by using Package Definition Files (*.sms) provided by our packaging team.
If I create the Software package filling manually the Attributes and Executing Put in the end, it works fine. Software Package is correctly created. (replace SCCM Server and XXX values below by yours)
$packageClass = [WMICLASS]"\\SCCMSERVER\root\sms\site_XXX:SMS_Package"
$newPackage = $packageClass.createInstance()
$newPackage.Name = "My Test Program"
$newPackage.Version = "0004.200"
$newPackage.Manufacturer = "TEST"
$newPackage.Language = "English"
$newPackage.Description = "Test package to test Powershell/WMI scripting Package Creation"
$newPackage.PkgSourceFlag = 2
$newPackage.PkgSourcePath = "\\SERVERNAME\SHARE$\TEST\PATH2PACKAGE"
$newPackage.Put()
If I manually Create the Package from the Console using the New Package from Definition it also works well (Package and Programs are correctly Created (Test.sms file used for the test copied below after my signature; It is dummy)
If I try to use Powershell/WMI to create the Package from the *.sms file using SMS_PDF_Package Class, when I get the package Object, after setting the PkgSourcePath and trying to execute Put, I get the following error:
Method invocation failed because [System.Management.ManagementBaseObject] doesn't contain a method named 'Put'.
At C:\Test\TestCreatePackagefromPDF.ps1:10 char:1+ $newPackage.Put()+ ~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFound
The code used is the following:
$PDFPackagePath = "C:\TEMP\Test.sms"
$PDFPackage = [IO.File]::ReadAlltext($PDFPackagePath)
$PackagePDFClass = [WMICLASS]"\\SCCMSERVER\root\sms\site_XXX:SMS_PDF_Package"
$PkgPDFID = $PackagePDFClass.LoadPDF($PDFPackagePath,$PDFPackage)
$Obj = $PackagePDFClass.GetPDFData($PkgPDFID.PDFID)
$newPackage = $Obj.PackageData
$Programs = $Obj.ProgramData
$newPackage.PkgSourceFlag = 2
$newPackage.PkgSourcePath = "\\SERVERNAME\SHARE$\TEST\PATH2PACKAGE"
$newPackage.Put()
If I compare the Objects $newPackage in both codes I get the same info. But in the first case I am able to save the Package by running Put() and in the second case I cannot as I get the error above.
The variable $Programs also contain an array to the 2 programs (install, remove) defined in the sms. I am not even able to process them as I couldn't manage to get the Software Package saved first.
Anyone could tell me what I am doing wrong??
Many thanks in advanve
Ramon
Test.sms content pasted below
[PDF]
VERSION=2.0
[PACKAGE DEFINITION]
NAME=Test Package for Powershell/WMI
VERSION=1.0
LANGUAGE=Multilanguage
PUBLISHER=TEST
COMMENT=Test package to test Powershell/WMI scripting Package Creation from PDF
MIFFILENAME=TEST_MSI_PROGRAM
MIFNAME=TEST_MSI_PROGRAM
programs=install,remove
[install]
NAME=TEST_MSI_PROGRAM install
COMMANDLINE=TEST_MSI_PROGRAM_INSTALL.cmd
UserInputRequired=False
AdminRightsRequired=True
DriveLetterConnection=False
CanRunWhen=AnyUserStatus
Run=Hidden
[remove]
NAME=TEST_MSI_PROGRAM remove
COMMANDLINE=TEST_MSI_PROGRAM_REMOVE.cmd
UserInputRequired=False
AdminRightsRequired=True
DriveLetterConnection=False
CanRunWhen=AnyUserStatus
Run=Hidden
Cheers Ramon Jiménez