Here’s a PowerShell script we recently wrote to show the source path location for all the content that we put into ConfigMgr. The Script lists all the content source paths for the following CM objects.
- Applications
- Driver Packages
- Drivers
- Boot Images
- OS Images
- Software Update Package Groups
- Packages
The output is as shown in the example below.
before executing the script, connect to your site.
clear-host function GetInfoPackages() { $xPackages = Get-CMPackage | Select-object Name, PkgSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoDriverPackage() { $xPackages = Get-CMDriverPackage | Select-object Name, PkgSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoBootimage() { $xPackages = Get-CMBootImage | Select-object Name, PkgSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoOSImage() { $xPackages = Get-CMOperatingSystemImage | Select-object Name, PkgSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoDriver() { $xPackages = Get-CMDriver | Select-object LocalizedDisplayName, ContentSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.LocalizedDisplayName $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.ContentSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoSWUpdatePackage() { $xPackages = Get-CMSoftwareUpdateDeploymentPackage | Select-object Name, PkgSourcePath, PackageID $info = @() foreach ($xpack in $xPackages) { #write-host $xpack.Name $object = New-Object -TypeName PSObject $object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name $object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath $object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID $info += $object } $info } function GetInfoApplications { foreach ($Application in Get-CMApplication) { $AppMgmt = ([xml]$Application.SDMPackageXML).AppMgmtDigest $AppName = $AppMgmt.Application.DisplayInfo.FirstChild.Title foreach ($DeploymentType in $AppMgmt.DeploymentType) { # Calculate Size and convert to MB $size = 0 foreach ($MyFile in $DeploymentType.Installer.Contents.Content.File) { $size += [int]($MyFile.GetAttribute("Size")) } $size = [math]::truncate($size/1MB) # Fill properties $AppData = @{ AppName = $AppName Location = $DeploymentType.Installer.Contents.Content.Location DeploymentTypeName = $DeploymentType.Title.InnerText Technology = $DeploymentType.Installer.Technology ContentId = $DeploymentType.Installer.Contents.Content.ContentId SizeMB = $size } # Create object $Object = New-Object PSObject -Property $AppData # Return it $Object } } } # Get the Data Write-host "Applications" -ForegroundColor Yellow GetInfoApplications | select-object AppName, Location, Technology | Format-Table -AutoSize Write-host "Driver Packages" -ForegroundColor Yellow GetInfoDriverPackage | Format-Table -AutoSize Write-host "Drivers" -ForegroundColor Yellow GetInfoDriver | Format-Table -AutoSize Write-host "Boot Images" -ForegroundColor Yellow GetInfoBootimage | Format-Table -AutoSize Write-host "OS Images" -ForegroundColor Yellow GetInfoOSImage | Format-Table -AutoSize Write-host "Software Update Package Groups" -ForegroundColor Yellow GetInfoSWUpdatePackage | Format-Table -AutoSize Write-host "Packages" -ForegroundColor Yellow GetInfoPackages | Format-Table -AutoSize
Thanks to Claude Henchoz for helping me out with the the Applications function.
I realize that this post is almost a year old but what version of SCCM 2012 did you write this against? R2, SP1, etc? I’m asking because I tried running this against our SP1 install and ($Application.SDMPackageXML).AppMgmtDigest returns nothing.
Hi, i wrote this when we had 2012 sp1 in place, meanwhile we run R2 , but haven’t tested it there yet.
I’m getting a lot of errors when trying to run the above powershell script. Syntax errors, like, “Missing ‘)’ in method call”, and “Missing closing ‘}'”, stuff like that. I’m trying to run this on Server 2012 w/SCCM 2012R2. Is there something I’m doing wrong?
Replace " with double quotes.
Had the same problem as Matt; looks like the text of script changes a single quote ‘ to ".
Find " and replace with ‘ (there are a lots of them!) and all will be OK. And running it on 2012R2 with SP1 + CU1, so ‘latest’ works OK.
Nice script though otherwise. Thanks!
OK, don’t you just love how a page changes what you put? The text to find is & (ampersand) quot ; (semi-colon) without any spaces…
Hi guys,
I still cannot get the script to run…
There is no singel ( ‘ ) or double ( ” ) quotes to find.
What do I need to change to make the script run?
“The text to find is & (ampersand) quot ; (semi-colon) without any spaces…”
What does that mean?
Clearly the person who posted this blog was too lazy to simply upload a text file to a storage site, so people dont have to mess around trying to account for all the issues that this bloging website cause with scripts.
Can someone please clarify what is needed to make this script work????
Here is the array of errors it causes:
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:53
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
Missing ‘)’ in method call.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:53
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
Unexpected token ‘&’ in expression or statement.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:53
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
Missing closing ‘)’ in expression.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:63
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks (“&”) to pass it as part of a string.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:124 char:82
+ … .Content.File) {
+ ~
Missing closing ‘}’ in statement block.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:120 char:62
+ foreach ($DeploymentType in $AppMgmt.DeploymentType) {
+ ~
Missing closing ‘}’ in statement block.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:115 char:49
+ foreach ($Application in Get-CMApplication) {
+ ~
Missing closing ‘}’ in statement block.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:113 char:30
+ function GetInfoApplications {
+ ~
Missing closing ‘}’ in statement block.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:69
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
Unexpected token ‘)’ in expression or statement.
At F:\SOFTWARE\_Non Packaged Software\SCCM\Scripts\Export_ALL_Content.ps1:125 char:70
+ $size += [int]($MyFile.GetAttribute("Size"))
+ ~
Unexpected token ‘)’ in expression or statement.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
For the benefit of others, here is the script with all the bad formatting tidied up:
http://1drv.ms/1RYZsUr
What a wonderful script! Worked like a charm on my SCCM 2012 R2 SP1 CU3. The only thing that you need is to Find&Replace " with ‘
If someone could improve the script to format output as a table to simply insert in Excel and filter, that would be really appreciated. Currently when I insert its output in Excel, it puts everything in the same first column.
In the script listing, ” will appear as &quоt;
Great script just what i needed, thanks!
For anyone that is a bit confused you need to change the " (amp, quot and 😉 to ‘ ‘ (single quotes)
Example – Write-host "Applications" -ForegroundColor Yellow change this to:
Write-host ‘Applications’ -ForegroundColor Yellow
The issue is because " is code for HTML
Corrected Script
clear-host
function GetInfoPackages()
{
$xPackages = Get-CMPackage | Select-object Name, PkgSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoDriverPackage()
{
$xPackages = Get-CMDriverPackage | Select-object Name, PkgSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoBootimage()
{
$xPackages = Get-CMBootImage | Select-object Name, PkgSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoOSImage()
{
$xPackages = Get-CMOperatingSystemImage | Select-object Name, PkgSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoDriver()
{
$xPackages = Get-CMDriver | Select-object LocalizedDisplayName, ContentSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.LocalizedDisplayName
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.ContentSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoSWUpdatePackage()
{
$xPackages = Get-CMSoftwareUpdateDeploymentPackage | Select-object Name, PkgSourcePath, PackageID
$info = @()
foreach ($xpack in $xPackages)
{
#write-host $xpack.Name
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Package -Value $xpack.Name
$object | Add-Member -MemberType NoteProperty -Name SourceDir -Value $xpack.PkgSourcePath
$object | Add-Member -MemberType NoteProperty -Name PackageID -Value $xpack.PackageID
$info += $object
}
$info
}
function GetInfoApplications {
foreach ($Application in Get-CMApplication) {
$AppMgmt = ([xml]$Application.SDMPackageXML).AppMgmtDigest
$AppName = $AppMgmt.Application.DisplayInfo.FirstChild.Title
foreach ($DeploymentType in $AppMgmt.DeploymentType) {
# Calculate Size and convert to MB
$size = 0
foreach ($MyFile in $DeploymentType.Installer.Contents.Content.File) {
$size += [int64]($MyFile.GetAttribute(“Size”))
}
$size = [math]::truncate($size/1MB)
# Fill properties
$AppData = @{
AppName = $AppName
Location = $DeploymentType.Installer.Contents.Content.Location
DeploymentTypeName = $DeploymentType.Title.InnerText
Technology = $DeploymentType.Installer.Technology
ContentId = $DeploymentType.Installer.Contents.Content.ContentId
SizeMB = $size
}
# Create object
$Object = New-Object PSObject -Property $AppData
# Return it
$Object
}
}
}
# Get the Data
Write-host “Applications” -ForegroundColor Yellow
GetInfoApplications | select-object AppName, Location, Technology | Format-Table -AutoSize
Write-host “Driver Packages” -ForegroundColor Yellow
GetInfoDriverPackage | Format-Table -AutoSize
Write-host “Drivers” -ForegroundColor Yellow
GetInfoDriver | Format-Table -AutoSize
Write-host “Boot Images” -ForegroundColor Yellow
GetInfoBootimage | Format-Table -AutoSize
Write-host “OS Images” -ForegroundColor Yellow
GetInfoOSImage | Format-Table -AutoSize
Write-host “Software Update Package Groups” -ForegroundColor Yellow
GetInfoSWUpdatePackage | Format-Table -AutoSize
Write-host “Packages” -ForegroundColor Yellow
GetInfoPackages | Format-Table -AutoSize
Thanks, I needed Application part, this was super useful and very easy – working great. Cheers!