Created
March 31, 2015 13:52
-
-
Save XPlantefeve/6eae4d47fad7712ad04d to your computer and use it in GitHub Desktop.
Reads computer info from a surveyor database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Gets computer information from Surveyor | |
.DESCRIPTION | |
Returns computers from the Surveyor database. Can return information for | |
specific computers or a filtered subset of the DB table. | |
.EXAMPLE | |
Get-SurveyorComputer -Name MyComputerName | |
Returns information for the computer named MyComputerName. | |
.EXAMPLE | |
Get-SurveyorComputer -Filter 'client_name = "MyComputerName"' | |
Returns information for the computer named MyComputerName. | |
#> | |
Function Get-SurveyorComputer | |
{ | |
[CmdletBinding(DefaultParameterSetName = 'name')] | |
[OutputType([System.Data.DataRow])] | |
Param | |
( | |
# Computer Name | |
[Parameter(Mandatory = $False, | |
ValueFromPipeline = $true, | |
ValueFromPipelineByPropertyName = $true, | |
ParameterSetName = 'name', | |
Position = 0)] | |
[Alias('ComputerName')] | |
[string[]]$Name, | |
# Filter(s). It will be passed to the SQL request, so the format is that of | |
# SQL: "client_name='mycomputername'" | |
[string[]]$Filter | |
) | |
Begin | |
{ | |
# $Filters = @() | |
$con = Open-SQLServer -Server SERVERNAME -Database SurveyorDB | |
} | |
Process | |
{ | |
If ($Name) | |
{ | |
$Filter += "Client_Name = '$Name'" | |
} | |
If ($Filter.count -gt 0) | |
{ | |
$WhereClause = 'WHERE ' + ( $Filter -join ' AND ' ) | |
} | |
Write-Debug $WhereClause | |
Update-TypeData -TypeName Surveyor.ComputerInfo -DefaultDisplayPropertySet client_name, last_user_name, mac_address_text, client_description_text, ip_address_text, bios_text, group_name, is_preferred_proxy -Force | |
Update-TypeData -TypeName Surveyor.ComputerInfo -MemberType AliasProperty -MemberName Name -Value client_name -Force | |
Get-SQLData -con $con -SQL "SELECT * FROM tblclient ${WhereClause}" -AddType Surveyor.ComputerInfo | |
} | |
End | |
{ | |
Close-SQLServer -con $con | |
} | |
} | |
New-Alias -Name svcomp -Value Get-SurveyorComputer -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment