Public/Get-PdqInventoryComputerData.ps1
<#
.SYNOPSIS Retrieves all rows from the specified table for the specified ComputerId. .INPUTS None. .OUTPUTS System.Object[] .EXAMPLE Get-PdqInventoryComputerData -Name 'CEO-PC' -Table 'NetworkAdapters' -Columns 'Name', 'MacAddress' #> function Get-PdqInventoryComputerData { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] # The name or hostname of the computer you would like to retrieve data for. [String]$Name, [Parameter(Mandatory = $true)] # The database table you would like to query. # Use the following command to see a list of available tables: # Get-PdqDatabaseTables -Product 'Inventory' [String]$Table, [Parameter(Mandatory = $true)] # The columns of the database table you would like to see. # Use Get-PdqDatabaseColumns to see the available columns for your desired table. [String[]]$Columns, # Don't throw an error if no data is returned. [Switch]$AllowNull, # The path to the currently active database will be retrieved by default. # You can use this parameter if you wish to run this function against a different database. [String]$DatabasePath ) try { $CloseConnection = Open-PdqSqlConnection -Product 'Inventory' -DatabasePath $DatabasePath $ColumnsJoined = $Columns -join ', ' $Query = "SELECT $ColumnsJoined FROM $Table WHERE ComputerId = @ComputerId;" $ComputerId = Resolve-PdqInventoryComputerName -Name $Name $Params = @{ 'ComputerId' = $ComputerId } $ComputerData = Invoke-SqlQuery -Query $Query -ConnectionName 'Inventory' -Parameters $Params if ( (-not $ComputerData) -and (-not $AllowNull) ) { throw "No data was found in the $Table table for: $Name." } $ComputerData } finally { Close-PdqSqlConnection -Product 'Inventory' -CloseConnection $CloseConnection } } |