PowerShell and Admin AutomationReporting and AuditsIntermediate1-2 hoursLab build

Build a Reusable PowerShell Script for Software Inventory Reporting

Build a reusable PowerShell software inventory script that exports clean CSV reports from Windows endpoints.

Last reviewed4/30/2026
software inventory
PowerShellWindows Management Instrumentation (WMI)CSV

Expected Outcome

A reusable PowerShell script that can be executed on multiple Windows endpoints to generate CSV reports of installed software, supporting software audits and compliance checks.

Assumptions

  • Basic understanding of PowerShell
  • Access to Windows endpoints with administrative privileges
  • PowerShell version 5.1 or higher

Bill of Materials

  • Windows PowerShell
  • Text editor (e.g., Visual Studio Code, Notepad++)
  • CSV file viewer (e.g., Microsoft Excel)

Build Steps

  1. Step 1: Open PowerShell ISE or a text editor

    Launch PowerShell ISE or your preferred text editor to start writing the script.

  2. Step 2: Define the output file path

    Set a variable for the output CSV file path where the inventory report will be saved.

    Example pattern only. Adjust for your environment before running.

    $outputPath = 'C:\SoftwareInventoryReport.csv'
  3. Step 3: Retrieve installed software

    Use the Get-WmiObject cmdlet to retrieve the list of installed software from the local machine. Manual action: $installedSoftware = Get-WmiObject -Class Win32_Product | Select-Object Name, Version, Vendor.

  4. Step 4: Export the data to CSV

    Export the collected software inventory data to a CSV file using the Export-Csv cmdlet.

    Example pattern only. Adjust for your environment before running.

    $installedSoftware | Export-Csv -Path $outputPath -NoTypeInformation
  5. Step 5: Add error handling

    Implement error handling to manage any issues that may arise during the execution of the script.

    Example pattern only. Adjust for your environment before running.

    try {
    # Code to retrieve and export software
    } catch {
    Write-Host 'An error occurred: ' $_.Exception.Message
    }
  6. Step 6: Save and test the script

    Save the script with a .ps1 extension and run it to test its functionality.

    Example pattern only. Adjust for your environment before running.

    Save-Module -Name 'SoftwareInventory.ps1'
    .\SoftwareInventory.ps1
  7. Step 7: Schedule the script (optional)

    Optionally, use Task Scheduler to run the script at regular intervals for ongoing inventory management.

Validation

  • Open the generated CSV file and verify that it contains the expected columns: Name, Version, and Vendor.
  • Run the script on multiple endpoints to ensure consistency in the output.

Troubleshooting

  • Check service logs before changing the design.
  • Confirm ports, paths, credentials, DNS names, and container names match the guide assumptions.

Cleanup or Rollback

  • Stop test services you no longer need and keep a copy of working configuration before deleting volumes or data directories.

Next Improvements

  • Enhance the script to include additional software details such as installation date.
  • Integrate the script with a centralized logging system for better tracking.
  • Create a user-friendly interface for non-technical users to run the script.