markhallen
3/17/2018 - 12:05 PM

A script to document all the software properties and settings including Software Name, Content Location, Installation program (command), the

A script to document all the software properties and settings including Software Name, Content Location, Installation program (command), the Uninstall program (command), and dependencies.

function Get-ConfigMgrSite
{
    [cmdletbinding()]

    Param()
    
    Begin{}
    
    Process{
        $ManagementPointSearcher = [adsisearcher]'ObjectClass=mssmsmanagementpoint'
        $ManagementPointADObject = $ManagementPointSearcher.FindOne().GetDirectoryEntry()
        
        [pscustomobject]@{
            SiteServer = $ManagementPointADObject.mssmsmpname[0]
            SiteCode   = $ManagementPointADObject.mssmssitecode[0]
            PSTypeName = 'ARTools.ConfigMgrSite'
        }
    }
    
    End{}
}

function Get-ConfigMgrAppInfo
{
    [cmdletbinding()]

    Param(
        [Parameter(Mandatory = $True,ValueFromPipelineByPropertyName = $True)]
        [Alias('LocalizedDisplayName')]
        [ArgumentCompleter({
            $TextToComplete = $args[2]

            $CMSite = Get-ConfigMgrSite

            $CompletionOptions = Get-WmiObject -ComputerName $CMSite.SiteServer -Namespace "root\SMS\site_$($CMSite.SiteCode)" -Class SMS_Application -Filter 'IsLatest=1' -ErrorAction SilentlyContinue | 
            Select-Object -ExpandProperty LocalizedDisplayName |
            Sort-Object

            foreach ($Item in $CompletionOptions.Where({$_ -like "*$TextToComplete*"}))
            {
                [CompletionResult]::new("`"$Item`"", $Item, [CompletionResultType]::ParameterValue, $Item)
            }
        })]
        [string]$ApplicationName,

        [Parameter()]
        [switch]$Raw
    )

    Begin{
        Push-Location
        
        Connect-ConfigMgr
    }

    Process{
        Get-CMApplication -Name $ApplicationName |
        
        ForEach-Object -Process {
            [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::Deserialize($_.SDMPackageXML) |

            Foreach-Object -Process{
                If(-not $Raw)
                {
                    $ApplicationName = $_.Title
                
                    $_.DeploymentTypes | 
                    Select-Object -Property @{n='ApplicationName';e={$ApplicationName}}, 
                    @{n='DeploymentTypeName';e={$_.Title}}, 
                    @{n='InstallCommandLine';e={$_.Installer.InstallCommandLine}}, 
                    @{n='UninstallCommandLine';e={$_.Installer.UninstallCommandLine}},
                    @{n='ContentLocation';e={$_.Installer.Contents.Location}},
                    @{n='Requirements';e={$_.Requirements.Name -join ",`r`n"}},
                    @{n='Dependencies';e={$_.Dependencies.Name -join ",`r`n"}}
                }
                Else{$_}
            }
        }
    }

    End{
        Pop-Location
    }
}