From c45afbff3f71a087962f3fa39014773d5f5becc4 Mon Sep 17 00:00:00 2001 From: Tyler Hale Date: Sat, 18 Sep 2021 08:06:42 -0600 Subject: [PATCH] Initial commit --- Get-Software.ps1 | 107 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 18 ++++---- 2 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 Get-Software.ps1 diff --git a/Get-Software.ps1 b/Get-Software.ps1 new file mode 100644 index 0000000..1b58b4b --- /dev/null +++ b/Get-Software.ps1 @@ -0,0 +1,107 @@ +<# + +.SYNOPSIS +Gathers a list of installed software on a given computer. + +.DESCRIPTION +Gathers the list of software installed for a given computer or set of computers. + +.PARAMETER Path +Path to use to export the CSV report. If the path is not specified, +results are output to the running terminal. + +.PARAMETER ComputerName +Specifies the computers on which the command runs. The default is the local computer. + +.PARAMETER Credential +Credential that should be used to connect to a remote machine. + +.NOTES + Version: 1.0 + Author: Tyler Hale + Creation Date: 2021.09.18 + +#> + +[CmdletBinding()] +param ( + [Parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [string] + $Path, + [Parameter(Mandatory = $false)] + [ValidateScript( {Test-Connection $_ -Count 2})] + [alias('Cn')] + [string[]] + $ComputerName = $env:COMPUTERNAME, + [Parameter(Mandatory=$false, ValueFromPipeline=$true)] + [ValidateNotNull()] + [System.Management.Automation.PSCredential] + [System.Management.Automation.Credential()] + $Credential = [System.Management.Automation.PSCredential]::Empty +) + +############################################### [Script Settings] ################################################ + +# Locations where software is registered +$RegistryPaths = @( + "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" + "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" +) + +############################################# [Internal Processing] ############################################## + +<# Build Remote Parameters #> +# Reference by appending @RemoteParameters to a command +$RemoteParameters = @{} + +if ($ComputerName -ne $env:COMPUTERNAME) { + Write-Verbose "Adding $ComputerName to Remote Parameters splat variable" + $RemoteParameters['ComputerName'] = $ComputerName +} + +if ($Credential -ne [System.Management.Automation.PSCredential]::Empty) { + Write-Verbose "Adding provided credentials to Remote Parameters splat variable" + $RemoteParameters['Credential'] = $Credential +} + +# Create Inventory variable +$SoftwareInventories = @() + +# Get the current date for logging +$DateCollected = (Get-Date -Format o) + +################################################## [Execution] ################################################### + +foreach ($Computer in $ComputerName) { + $SoftwareInventory = $null + + $SoftwareInventory = foreach ($RegistryEntry in $RegistryPaths) { + Write-Verbose "Processing $RegistryEntry" + + foreach ($Entry in (Invoke-command {Get-ItemProperty $args[0] } -ArgumentList $RegistryEntry @RemoteParameters)) { + # If DisplayName exists add it to the software inventory + if (($null,'' -ne $Entry.DisplayName)) { + [pscustomobject][ordered]@{ + "Name" = $Entry.DisplayName + "Version" = $Entry.DisplayVersion + "Publisher" = $Entry.Publisher + "Install Size" = $Entry.EstimatedSize + "Install Location" = $Entry.InstallLocation + "Uninstall String" = $Entry.UninstallString + "Computer Name" = $Computer + "Date Collected" = $DateCollected + } + } + } + } + $SoftwareInventories += $SoftwareInventory | Sort-Object Name +} + +if ($Path -ne "") { + $SoftwareInventories | Export-Csv $Path -Force -NoTypeInformation + Write-Host "Software Inventories have been exported to $Path" +} +else { + return $SoftwareInventories +} diff --git a/README.md b/README.md index 493b192..43d2ab8 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ # Get-Software -Gathers a list of installed software on a given machine. - -## Requirements +Gathers a list of installed software on a given computer or set of computers. ## Variables -| Variable | Required | Default | Choices | Description | -| -------- | -------- | ------- | ------- | ----------- | -| | | | | | +| Variable | Required | Default | Choices | Description | +| ------------ | -------- | ------------- | ------- | ------------------------------------------------------------- | +| Path | No | | | Path to use to export the CSV report | +| ComputerName | No | Local Machine | | Specifies the computers on which the command runs | +| Credential | No | Running User | | Credential that should be used to connect to a remote machine | ## Example +```powershell +.\Get-Software.ps1 +``` + ## License See LICENSE file for full license information. - -## Screenshots