Skip to content

R0mb0/OCS_Inventory_CSV_Exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ“¦ OCS Inventory CSV Exporter

A production-ready PowerShell + Playwright automation tool that logs into OCS Inventory, opens the advanced search page, enables all selectable table columns, and downloads a full CSV export with timestamped filenames.

Built for reliability, privacy, and unattended execution (Windows Task Scheduler friendly).

Codacy Badge Maintenance Open Source Love svg3 License: MIT PowerShell Playwright Node.js


πŸš€ Why this project exists

This project was created to solve a real operational constraint: in some enterprise environments, the server hosting OCS is heavily restricted and direct database access is not allowed by policy.

In this scenario, CSV export from the web interface becomes the only approved and realistic way to extract the data needed to build downstream internal applications, reports, or integrations.

The repository is published to help anyone facing the same limitation: automating reliable CSV extraction when the application database cannot be contacted directly.

✨ Features

  • Full-column export workflow: toggles all options in #select_colaffich_multi_crit before download.
  • Timestamped output files: e.g. 2026_03_10-14_30.csv.
  • Headless automation (default) for scheduled/background use.
  • Optional visible browser mode for troubleshooting and demos.
  • No hardcoded environment details: base URL and credentials are parameterized.
  • Detailed runtime logs printed to terminal with timestamps.
  • First-run dependency bootstrap: auto-installs Playwright when needed.

πŸ“ Repository structure

  • Script/ocs_export.ps1 β†’ main automation script
  • Script/examples.ps1 β†’ usage examples
  • README.md β†’ project documentation
  • LICENSE β†’ MIT license

πŸ”§ Requirements

  • Windows PowerShell 5.1+ (or PowerShell 7+)
  • Node.js LTS installed and available in PATH
  • Network access to your OCS instance
  • Valid OCS user credentials

βš™οΈ Parameters

The script is fully parameterized to avoid exposing private infrastructure details in code.

  • -BaseUrl (required): OCS base URL, e.g. https://your-server/ocsreports
  • -LoginUrl (optional): defaults to $BaseUrl/index.php
  • -SearchUrl (optional): defaults to standard OCS β€œlastcome” search URL
  • -Username (required): OCS username
  • -Password (optional): plain text password (less secure)
  • -PromptForPassword (optional switch): secure password prompt (recommended)
  • -OutputDirectory (optional): CSV destination directory
  • -TimestampFormat (optional): filename datetime format
  • -ShowBrowser (optional switch): run non-headless for visual debugging

▢️ Quick start

1) Open PowerShell in the repository script folder

cd .\OCS_Inventory_CSV_Exporter\Script

2) Run using secure password prompt (recommended)

.\ocs_export.ps1 `
  -BaseUrl "https://your-server/ocsreports" `
  -Username "your_user" `
  -PromptForPassword `
  -OutputDirectory "C:\Exports\OCS"

3) Run with visible browser (debug mode)

.\ocs_export.ps1 `
  -BaseUrl "https://your-server/ocsreports" `
  -Username "your_user" `
  -PromptForPassword `
  -ShowBrowser

4) Run with custom search URL (optional)

.\ocs_export.ps1 `
  -BaseUrl "https://your-server/ocsreports" `
  -SearchUrl "https://your-server/ocsreports/index.php?function=visu_search&fields=HARDWARE-LASTCOME&comp=tall&values=&values2=all&type_field=" `
  -Username "your_user" `
  -PromptForPassword

🧠 How the script works (technical flow)

  1. Validates prerequisites (node, Playwright runtime, output folder).
  2. Builds a temporary Node.js Playwright runner script.
  3. Opens OCS login page and authenticates using standard fields:
    • LOGIN
    • PASSWD
    • Valid_CNX submit action
  4. Loads the target search page.
  5. Finds #select_colaffich_multi_crit and iterates all options except default.
  6. Triggers selector changes to toggle/show all relevant columns.
  7. Clicks the export link with function=export_csv, tablename=affich_multi_crit, nolimit=true.
  8. Saves the downloaded CSV with a timestamped filename.
  9. Disposes browser context at the end to prevent stale cookie/session behavior.

πŸ—“οΈ Automate daily execution (Task Scheduler)

Recommended action:

powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\Script\ocs_export.ps1" -BaseUrl "https://your-server/ocsreports" -Username "your_user" -PromptForPassword -OutputDirectory "C:\Exports\OCS"

πŸ§ͺ Troubleshooting

  • Node.js not found β†’ install Node.js LTS and reopen terminal.
  • Playwright first run is slow β†’ expected; browser binaries are being installed.
  • HTML downloaded instead of CSV β†’ verify credentials, selectors, and current OCS UI layout.
  • Columns not fully expanded β†’ run with -ShowBrowser and inspect selector behavior in your OCS version.
  • Execution policy errors β†’ use -ExecutionPolicy Bypass in scheduled command.

πŸ› οΈ Development notes

  • The solution intentionally uses browser automation because some OCS setups depend on runtime UI state for export correctness.
  • Pure HTTP approaches may fail in environments with CSRF/session-dependent DataTables behavior.
  • This tool is especially useful when policy constraints prevent direct database-level extraction.
Not made by AI

About

PowerShell + Playwright automation to log into OCS Inventory, enable all hidden table columns, and export full CSV reports with timestamped filenames. Built for scheduled unattended runs with session cleanup and debug logging.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors