Tuesday, October 22, 2013

SQL query for packages and Source path of the packages

Below is the SQL query for a Task sequence ID” 'CE100053'” with referenced packages and Source path of the packages

SELECT     TOP (100) PERCENT ps.Name AS C062, ps.SourceVersion, ps.SourceDate, ps.Targeted AS NumberOfDPsTargeted0, ps.Installed AS NumberOfDPsInstalled0,
                      ps.Retrying AS NumberOfDPsRetrying0, ps.Failed AS NumberOfDPsFailed0, ps.SourceSite, ps.SourceSize, ps.SourceCompressedSize, ps.PackageID,
                      dbo.v_Package.PkgSourcePath AS [Pkg Source Path]
FROM         (SELECT DISTINCT ReferencePackageID AS PackageID
                       FROM          dbo.v_TaskSequenceReferencesInfo
                       WHERE      (PackageID = 'CE100053')) AS RefPkgs INNER JOIN
                      dbo.v_PackageStatusRootSummarizer AS ps ON ps.PackageID = RefPkgs.PackageID INNER JOIN
                      dbo.v_Package ON ps.PackageID = dbo.v_Package.PackageID

ORDER BY C062

Export the task sequence SCCM 2012 to XML format (legacy format of sccm 2007)

Export the task sequence SCCM 2012 to XML format (legacy format of sccm 2007)

SCCM 2012 task sequences can be exported in .zip format and when we handle/extract it will not work.

Below is only applicable from sccm 2012 SP1 and above

With help of Power shell we can extract this in XML format. 
 
Import-Module "C:Program Files (x86)Microsoft Configuration ManagerAdminConsolebinConfigurationManager.psd1"
(Get-CMTaskSequence | Where-Object {$_.Name -eq "TEST_TS"}).Sequence | Out-File c:tempTSsequence.txt


For Importing
 
param (
[string]$SiteCode,
[string]$TaskSequenceName,
[string]$InputFile
)
#########
# What does it do?
# Script imports a previously "exported" TaskSequence from CM12 to CM12
#
# Howto: Extract the TaskSequence with the following command:
# (Get-CMTaskSequence | where-object {$_.Name -eq $NameOfTaskSequence}).Sequence | Out-File $PathToExportFile
# This will be your $InputFile
#
# Author: David O'Brien, david.obrien@sepago.de
# Created: 28.09.2012
# Prerequisites:
#               - Microsoft System Center Configuration Manager 2012 SP1 (beta)
#               - ConfigMgr Powershell to get your existing TaskSequence
#
#########
$Class = "SMS_TaskSequencePackage"
$Instance = $null
$TS = $null
$NewSequence = $null
$TS = [wmiclass]"\.rootsmssite_$($SiteCode):$($Class)"
$Instance = $TS.CreateInstance()
$SequenceFile = Get-Content $InputFile
$NewSequence = $Ts.ImportSequence($SequenceFile).TaskSequence
$Instance.Name = "$TaskSequenceName"
$NewTSPackageID = $TS.SetSequence($Instance, $NewSequence).SavedTaskSequencePackagePath