SCRIPT : créer un package SCCM et le programme d’installation associé
Voici un script Powershell inspiré du SDK de SCCM vous permettant de créer un package SCCM et le programme d’installation associé
1: [system.reflection.assembly]::loadfrom("C:\Program Files\Microsoft Configuration Manager\AdminUI\bin\adminui.wqlqueryengine.dll")
2: [system.reflection.assembly]::loadfrom("C:\Program Files\Microsoft Configuration Manager\AdminUI\bin\microsoft.configurationmanagement.managementprovider.dll")
3:
4: # déclaration des constantes
5:
6: $newPackageName = "package de test"
7: $newPackageDescription = "Package cree a partir de powershell"
8: $newPackageSourceFlag = 3
9: $newPackageSourcePath = "\\Serveur1\sources\test"
10:
11: $newProgramName = "Installation"
12: $newProgramComment = "Programme d'installation cree a partir de powershell"
13: $newProgramCommandLine = "cscript installation.wsf"
14: $newProgramMaxRunTime = 0
15:
16: # declaration des variables
17:
18: $namedValues = New-Object -TypeName Microsoft.ConfigurationManagement.ManagementProvider.SmsNamedValuesDictionary
19: $connection = New-Object -TypeName Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlConnectionManager -ArgumentList $namedValues
20:
21: # connection au serveur sccm local
22:
23: $connection.Connect([System.Net.Dns]::GetHostName().ToUpper())
24:
25: # création du package
26:
27: $newPackage = $connection.CreateInstance("SMS_Package")
28:
29: #Populate new package properties.
30:
31: $newPackage["Name"].StringValue = $newPackageName
32: $newPackage["Description"].StringValue = $newPackageDescription
33: $newPackage["PkgSourceFlag"].IntegerValue = $newPackageSourceFlag
34: $newPackage["PkgSourcePath"].StringValue = $newPackageSourcePath
35:
36: # sauvegarde des parametres du package
37:
38: $newPackage.Put()
39: $newPackage.Get()
40:
41: # affichage des propriétés du package
42:
43: write-host "INFO : package cree : " $newPackageName
44: write-host "INFO : Package ID : " + $newPackage["PackageID"].StringValue
45:
46: # Création du programme
47:
48: $newProgram = $connection.CreateInstance("SMS_Program")
49:
50: # renseignement des propriétés du programme
51:
52: $newProgram["PackageID"].StringValue = $newPackage["PackageID"].StringValue
53: $newProgram["ProgramName"].StringValue = $newProgramName
54: $newProgram["Comment"].StringValue = $newProgramComment
55: $newProgram["CommandLine"].StringValue = $newProgramCommandLine
56: $newProgram["Duration"].IntegerValue = $newProgramMaxRunTime
57:
58: # sauvegarde des parametres du programme
59:
60: $newProgram.Put();
61:
62: write-host "INFO : Programme cree: " $newProgramName