test-examples.ps1

#!/usr/bin/env pwsh
<#
.SYNOPSIS
    Example usage and tests for GetLinuxDevices module.

.DESCRIPTION
    Demonstrates various ways to use the GetLinuxDevices module cmdlets.
#>


Import-Module ./GetLinuxDevices.psd1 -Force

Write-Host "`n=== GetLinuxDevices Examples ===" -ForegroundColor Cyan

# Example 1: List all USB devices
Write-Host "`n1. List all USB devices:" -ForegroundColor Green
Get-UsbDevice | Format-Table

# Example 2: Find specific USB vendor (SteelSeries)
Write-Host "`n2. Find SteelSeries USB devices:" -ForegroundColor Green
lsusb | Where-Object { $_.Vendor -like '*SteelSeries*' } | Format-List

# Example 3: Get all graphics cards
Write-Host "`n3. Find graphics cards:" -ForegroundColor Green
lspci | Where-Object { $_.Class -like '*VGA*' -or $_.Class -like '*3D*' } | Format-Table

# Example 4: Find network controllers
Write-Host "`n4. Find network controllers:" -ForegroundColor Green
lspci | Where-Object { $_.Class -like '*Network*' -or $_.Class -like '*Ethernet*' } | Format-Table

# Example 5: List only physical disks
Write-Host "`n5. List physical disks:" -ForegroundColor Green
lsblk | Where-Object { $_.Type -eq 'disk' } | Format-Table Name, Size, Model

# Example 6: Show mounted filesystems
Write-Host "`n6. Show mounted filesystems:" -ForegroundColor Green
lsblk | Where-Object { $_.MountPoint } | Format-Table Name, Size, FileSystem, MountPoint

# Example 7: Export USB devices to JSON
Write-Host "`n7. Export USB devices to JSON:" -ForegroundColor Green
$usbJson = lsusb | ConvertTo-Json -Depth 3
Write-Host "Exported $(($usbJson | ConvertFrom-Json).Count) USB devices"

# Example 8: Group PCI devices by class
Write-Host "`n8. Group PCI devices by class:" -ForegroundColor Green
lspci | Group-Object -Property Class | Sort-Object Count -Descending | Format-Table Count, Name

# Example 9: Find USB devices by ID pattern
Write-Host "`n9. Find Intel USB devices:" -ForegroundColor Green
lsusb | Where-Object { $_.Name -like '*Intel*' } | Format-Table

# Example 10: Calculate total disk space
Write-Host "`n10. Calculate total disk space:" -ForegroundColor Green
$disks = lsblk | Where-Object { $_.Type -eq 'disk' }
Write-Host "Found $($disks.Count) physical disk(s)"
$disks | Format-Table Name, Size, Model

Write-Host "`n=== Tests Complete ===" -ForegroundColor Cyan