2024-06-11 18:27:55 +00:00
param (
$examplePC
)
2024-07-26 23:04:17 +00:00
$GetPCNotInstalledApps = @ (
" Citrix " ,
" Microsoft Visual C\+\+ " ,
" RightFax " ,
" Windows Driver Package "
)
2024-06-11 18:27:55 +00:00
function Get-AppDiff {
param (
[ Parameter ( Mandatory ) ]
$pc ,
$TableView = $false
)
# Compares a pc's apps with a list of expected apps to see if the pc has any
# extra apps that we need to consider downloading
$apps = Get-Apps $pc
2024-09-18 18:15:13 +00:00
Write-Progress -Activity " Filtering out standard apps from $pc " -Status 'Removing version numbers and loading reference' -PercentComplete 10 -ParentId 1
2024-06-11 18:27:55 +00:00
$apps = Remove-Version $apps
# Open example file
$lookupTablePath = Join-Path ( get-item $PSScriptRoot ) . Parent . FullName 'Data\ExpectedApps.json'
$example = get-content $lookupTablePath | ConvertFrom-Json
2024-07-26 23:04:17 +00:00
# Open file with manually added apps to ignore
$lookupTablePath = Join-Path ( get-item $PSScriptRoot ) . Parent . FullName 'Data\AppsToIgnore.json'
$ignore = get-content $lookupTablePath | ConvertFrom-Json
$exclude = $example + $ignore
2024-06-11 18:27:55 +00:00
$output = @ ( )
# Finds each app that isn't in the example
2024-09-18 18:15:13 +00:00
$appi = 0
2024-06-11 18:27:55 +00:00
foreach ( $app in $apps ) {
2024-09-18 18:15:13 +00:00
$appi + +
Write-Progress -Activity " Filtering out standard apps from $pc " -Status " Checking $( $app . DisplayName ) " -PercentComplete ( ( $appi * 90 / $apps . Length ) + 10 ) -ParentId 1
2024-07-26 23:04:17 +00:00
$skip = $false
foreach ( $notapp in $GetPCNotInstalledApps ) {
if ( $app . DisplayName -match $notapp ) {
$skip = $true
break
}
2024-06-11 18:27:55 +00:00
}
2024-07-26 23:04:17 +00:00
if ( $skip -or $exclude . DisplayName -contains $app . DisplayName ) { continue }
$output + = $app
2024-06-11 18:27:55 +00:00
}
2024-09-18 18:15:13 +00:00
Write-Progress -Activity " Filtering out standard apps from $pc " -Status " Checking $app " -PercentComplete ( ( $appi * 90 / $apps . Length ) + 10 ) -ParentId 1
2024-06-11 18:27:55 +00:00
if ( $TableView ) {
2024-09-18 18:15:13 +00:00
$output | Out-GridView -Title " Get-PC Apps - $pc "
2024-06-11 18:27:55 +00:00
}
else {
Write-Output $output
}
}
# Function parses get-pc -apps output to extract just the name, not the
# version number or other unnecessary info
function Remove-Version {
param ( $apps )
$output = @ ( )
foreach ( $app in $apps ) {
if ( $null -eq $app . DisplayName ) { continue }
# Strip out the version details
# " - " might filter out too much, not sure
$separator = " `t " , " " , " - "
$option = [ System.StringSplitOptions ] :: RemoveEmptyEntries
$app . DisplayName = $app . DisplayName . Split ( $separator , $option ) [ 0 ]
$output + = $app
}
Write-Output $output
}
function Copy-FileNoDestruct ( $srcpath , $dstpath ) {
while ( $true ) {
if ( Test-Path $dstpath ) {
$dstpath + = " .bak "
} else {
Copy-Item -Path $srcpath -Destination $dstpath
return
}
}
}
function Get-ExampleApps {
param ( $examplePC )
$appsPath = ( Join-Path ( get-item $PSScriptRoot ) . Parent . FullName 'Private\Apps.ps1' )
2024-07-26 23:04:17 +00:00
$sccmPath = ( Join-Path ( get-item $PSScriptRoot ) . Parent . FullName 'Private\SCCMQuery.ps1' )
2024-06-11 18:27:55 +00:00
Import-Module -Force $appsPath
2024-07-26 23:04:17 +00:00
Import-Module -Force $sccmPath
$apps = Get-Apps $examplePC | Select-Object -Property " DisplayName "
$trimmedApps = @ ( )
foreach ( $app in $apps ) {
$skip = $false
foreach ( $notapp in $GetPCNotInstalledApps ) {
if ( ! $app . DisplayName -or $app . DisplayName -match $notapp ) {
$skip = $true
break
}
}
if ( $skip ) { continue }
$trimmedApps + = $app
}
$apps = Remove-Version $trimmedApps
2024-06-11 18:27:55 +00:00
# Open example file
$lookupTablePath = Join-Path ( get-item $PSScriptRoot ) . Parent . FullName 'Data\ExpectedApps.json'
Copy-FileNoDestruct $lookupTablePath $ ( $lookupTablePath + " .bak " )
Write-Host " Writing expected apps to " $lookupTablePath
$apps | ConvertTo-Json | Out-File $lookupTablePath
}
if ( $examplePC ) {
Get-ExampleApps $examplePC
}