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).
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.
- Full-column export workflow: toggles all options in
#select_colaffich_multi_critbefore 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.
Script/ocs_export.ps1β main automation scriptScript/examples.ps1β usage examplesREADME.mdβ project documentationLICENSEβ MIT license
- 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
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
cd .\OCS_Inventory_CSV_Exporter\Script.\ocs_export.ps1 `
-BaseUrl "https://your-server/ocsreports" `
-Username "your_user" `
-PromptForPassword `
-OutputDirectory "C:\Exports\OCS".\ocs_export.ps1 `
-BaseUrl "https://your-server/ocsreports" `
-Username "your_user" `
-PromptForPassword `
-ShowBrowser.\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- Validates prerequisites (
node, Playwright runtime, output folder). - Builds a temporary Node.js Playwright runner script.
- Opens OCS login page and authenticates using standard fields:
LOGINPASSWDValid_CNXsubmit action
- Loads the target search page.
- Finds
#select_colaffich_multi_critand iterates all options exceptdefault. - Triggers selector changes to toggle/show all relevant columns.
- Clicks the export link with
function=export_csv,tablename=affich_multi_crit,nolimit=true. - Saves the downloaded CSV with a timestamped filename.
- Disposes browser context at the end to prevent stale cookie/session behavior.
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"- 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
-ShowBrowserand inspect selector behavior in your OCS version. - Execution policy errors β use
-ExecutionPolicy Bypassin scheduled command.
- 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.