Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Du ändrar distributionspaketkällan för ett distributionspaket för programuppdateringar i Configuration Manager genom att hämta en instans av klassen SMS_SoftwareUpdatesPackage och med hjälp av metoden ValidateNewPackageSource.
Obs!
Paketkällan för de flesta andra typer av paket kan ändras i -konsolen. Det här alternativet är dock inte tillgängligt för programuppdateringspaket.
Så här ändrar du distributionspaketkällan
Konfigurera en anslutning till SMS-providern.
Hämta ett befintligt paketobjekt med hjälp
SMS_SoftwareUpdatesPackage
av klassen .Verifiera paketkällan med hjälp
ValidateNewPackageSource
av metoden .Ändra paketkällan för ett befintligt programuppdateringsdistributionspaket genom att ändra
PkgSourcePath
paketets egenskap.
Exempel
Följande exempelmetod visar hur du ändrar distributionspaketkällan för ett programuppdateringsdistributionspaket med hjälp SMS_SoftwareUpdatesPackage
av -klassen och ValidateNewPackageSource
-metoden.
Obs!
Alla uppdateringar som är tillgängliga i den gamla paketkällan måste vara tillgängliga i den nya paketkällan (innehållskällans sökväg, som skickas som variabeln newPackageSourceLocation
i skripten nedan).
Information om hur du anropar exempelkoden finns i Anropa Configuration Manager kodfragment.
Exempel på subrutinanropet i Visual Basic:
' PREWORK FOR ChangeDeploymentPackageSource
' Define the new package location to validate (package location must be UNC).
newPackageSourceLocation = "\\SMSSERVER\source1"
Call ChangeDeploymentPackageSource(swbemServices, _
"ABC00003", _
newPackageSourceLocation)
Exempel på metodanropet i C#:
//PREWORK FOR ChangeDeploymentPackageSource.
// Define the new package location to validate (package location must be UNC).
string newPackageSourceLocation = "\\\\SMSSERVER\\source1";
// Load the validateNewPackageSource parameters into an object to pass to the method.
Dictionary<string, object> validateNewPackageSourceParameters = new Dictionary<string, object>();
validateNewPackageSourceParameters.Add("PackageSource", newPackageSourceLocation);
//The method call.
SUMSnippets.ChangeDeploymentPackageSource(WMIConnection,
"ABC00003",
validateNewPackageSourceParameters,
newPackageSourceLocation);
Sub ChangeDeploymentPackageSource(connection, _
existingSUMPackageID, _
newDeploymentPackageLocation)
On Error Resume Next
' Get an existing SUM Deployment Package to change.
Set existingSUMDeploymentPackage = connection.Get("SMS_SoftwareUpdatesPackage.PackageID='" & existingSUMPackageID & "'")
' Check the package source for the existing SUM Deployment Package using the ValidateNewPackageSource method.
existingSUMDeploymentPackage.ValidateNewPackageSource(newDeploymentPackageLocation)
' Check the error information from the SWBemLasError object to determine success or failure of the ValidateNewPackageSource method.
If Err.Number = 0 Then
' Output a success message if the new package location is valid.
Wscript.Echo "The new location of the SUM deployment package validated. "
Wscript.Echo "Updating the SUM deployment package with the new package location. "
' Update the StoredPkgPath property of the existing deployment package
' with the new source location if the package location is valid.
existingSUMDeploymentPackage.PkgSourcePath = newDeploymentPackageLocation
' Save the updated package deployment package.
existingSUMDeploymentPackage.Put_
Else
' Output a failure message if the new deployment package location is not valid.
Wscript.Echo "The new location of the SUM deployment package failed to validate. "
End If
End Sub
public void ChangeDeploymentPackageSource(WqlConnectionManager connection,
string existingSUMPackageId,
Dictionary<string, object> validateNewPackageSourceParameters,
string newPackageSource)
{
try
{
// Get the specific SUM Deployment Package to change.
IResultObject existingSUMDeploymentPackage = connection.GetInstance(@"SMS_SoftwareUpdatesPackage.PackageId='" + existingSUMPackageId + "'");
// Validate the existing SUM Deployment Package content using the ValidateContent method.
// Note: The method will throw an exception, if the package source does not validate.
existingSUMDeploymentPackage.ExecuteMethod("ValidateNewPackageSource", validateNewPackageSourceParameters);
// Output a success message if the new package location is valid.
Console.WriteLine("The new location of the SUM deployment package validated. ");
// Update the PkgSourcePath property of the existing deployment package with the new source location.
existingSUMDeploymentPackage["PkgSourcePath"].StringValue = newPackageSource;
// Save the package properties.
existingSUMDeploymentPackage.Put();
// Output a success message that the package location was updated.
Console.WriteLine("Updated the SUM deployment package with the new package location. ");
}
catch (SmsException ex)
{
Console.WriteLine("Failed to validate the new package source.");
Console.WriteLine("Failed to update the SUM deployment package.");
Console.WriteLine("Error: " + ex.Message);
throw;
}
}
Exempelmetoden har följande parametrar:
Parameter | Typ | Beskrivning |
---|---|---|
connection |
-Hanterade: WqlConnectionManager – VBScript: SWbemServices |
En giltig anslutning till SMS-providern. |
existingSUMPackageID |
-Hanterade: String -Vbscript: String |
Paket-ID för ett befintligt programuppdateringsdistributionspaket. |
validateNewPackageSource |
– Hanterad: dictionary objekt |
validateNewPackageSource är ett ordlisteobjekt som innehåller de parametrar som ValidateNewPackageSource metoden kräver.PackageSource |
newPackageSourceLocation |
-Hanterade: String -Vbscript: String |
Källplatsen för det nya distributionspaketet. Källsökvägen måste vara en UNC-sökväg (Universal Naming Convention). Alla uppdateringar som är tillgängliga i den gamla paketkällan måste vara tillgängliga i den nya paketkällan. |
Kompilera koden
Det här C#-exemplet kräver:
Namnområden
System
System.Collections.Generic
System.Text
Microsoft. ConfigurationManagement.ManagementProvider
Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine
Församlingen
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Robust programmering
Mer information om felhantering finns i Om Configuration Manager fel.
.NET Framework Säkerhet
Mer information om hur du skyddar Configuration Manager program finns i Configuration Manager rollbaserad administration.
Se även
Om programuppdateringsdistributionerSMS_SoftwareUpdatesPackage
ValidateNewPackageSource-metod i klass SMS_SoftwareUpdatesPackage