Get-Product.ps1
# UPDATED: 2019-07-25 enum InstallState { BadConfiguration = -6 InvalidArgument = -2 UnknownPackage = -1 Advertised = 1 Absent = 2 Installed = 5 } class SoftwareProduct { [string]$Name [Version]$Version [InstallState]$InstallState [datetime]$InstallDate [Int32]$InstallAgeInDays [string]$InstallLocation [string]$PSComputerName } function Get-Product { <# .SYNOPSIS Ermittelt installiert Produkte .INPUTS System.String .OUTPUTS SoftwareProduct .PARAMETER Name Produktname oder ein Teil davon .PARAMETER ComputerName Eine Liste an Remotehosts .EXAMPLE Get-Product Array aller installierten Produkte auf. .EXAMPLE Get-Product -Name Office Array von Produkten die das Wort Office enthalten. .EXAMPLE Get-Product | Where-Object InstallDate -GT "2019-04-01" Array an Produkten die ab dem 1. April 2019 installiert wurden. .EXAMPLE Get-Product -ComputerName PC10, PC11, PC12 Array aller installierten Produkte von den Remoterechnern PC10, PC11 und PC12. .EXAMPLE Get-Product -Verbose Zeigt zusatzinformationen an. .EXAMPLE "Adobe", "Chrome" | Get-Product -ComputerName PC10, PC11, PC12 Array installierter Produkte die Adobe oder Chrome im Namen tragen von den Remoterechnern PC10, PC11 und PC12. .EXAMPLE Show-Command -Name Get-Product -NoCommonParameter -ErrorPopup | Out-GridView GUI bzgl. Ausfüllhilfe und Ergebnis. #> Param ( [Parameter(ValueFromPipeline = $true)] [ValidateLength(1, 255)] [String]$Name, [String[]]$ComputerName = "localhost" ) Begin { [datetime]$heute = (Get-Date).Date Write-Verbose -Message ("HEUTE: {0}" -f $heute) } Process { $query = @" SELECT Name , Version , InstallDate , InstallLocation , InstallState , __SERVER FROM Win32_Product WHERE Name LIKE '%$Name%' "@ Write-Verbose -Message ("WMI-QUERY: {0}" -f $query) Get-CimInstance -Query $query -ComputerName $ComputerName | ForEach-Object -Process { $result = [SoftwareProduct]@{ Name = $_.Name.Trim() Version = $_.Version InstallDate = [DateTime]::ParseExact($_.InstallDate, "yyyyMMdd", $null) InstallLocation = $_.InstallLocation InstallState = $_.InstallState PSComputerName = $_.PSComputerName } $result.InstallAgeInDays = ($heute - $result.InstallDate).Days return $result } } end { Remove-Variable -Name heute, query, result -Force -ErrorAction Ignore } } <# ! UTEST: Feature-Umfang Get-Help Get-Product -ShowWindow Show-Command -Name Get-Product -NoCommonParameter -ErrorPopup | Out-GridView Get-Product Get-Product -Name Office Get-Product | Out-GridView Get-Product | Where-Object InstallDate -GT "2019-04-01" Get-Product -ComputerName 192.168.107.127 Get-Product -ComputerName 192.168.107.127, 192.168.107.132, 192.168.107.136 Get-Product -Verbose "Adobe", "Chrome" | Get-Product "Adobe", "Chrome" | Get-Product -ComputerName 192.168.107.127, 192.168.107.132, 192.168.107.136 Get-Product -Name Office | Get-Member #> <# ! UTEST: Fehlbedienung TODO Z.Zt. keine bekannt #> |