Skip to content

Instantly share code, notes, and snippets.

@Chirishman
Last active May 16, 2018 23:03
Show Gist options
  • Save Chirishman/cc30ca0cdb2a5ca6aa8a7e1f324f6986 to your computer and use it in GitHub Desktop.
Save Chirishman/cc30ca0cdb2a5ca6aa8a7e1f324f6986 to your computer and use it in GitHub Desktop.
IronScripter Prequel 1
function Get-MonitorInfo {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:COMPUTERNAME
)
$MonitorSelect = @(
@{
N = 'ComputerName'
E = { $_.PSComputerName }
},
@{
N = 'ComputerType'
E = [scriptblock]::Create("'$(Get-CimInstance -Class Win32_ComputerSystem -ComputerName $ComputerName | select -ExpandProperty Model)'")
},
@{
N = 'ComputerSerial'
E = [scriptblock]::Create("'$(Get-CimInstance -Class Win32_Bios -ComputerName $ComputerName | select -ExpandProperty SerialNumber)'")
},
@{
N = 'MonitorSerial'
E = { (-join( $_.SerialNumberID | %{[char]$_ } )) | ?{$_ -ne 0} }
},
@{
N = 'MonitorType'
E = { (-join( $_.UserFriendlyName | %{[char]$_ } )) | ?{$_ -ne ''} }
}
)
Get-CimInstance -Class wmiMonitorID -namespace root\wmi -ComputerName $ComputerName | Select $MonitorSelect
}
@Chirishman
Copy link
Author

Chirishman commented May 16, 2018

  • Correct typos
  • Identify additional needed class (Win32_Bios)
  • Properly check nulls/zeroes
  • Add ComputerName parameter with a default value pointing to localhost
  • Use a select statement instead of creating multiple individual psobjects
  • Pre-define select statement and perform additional calls inside of the literal to reduce the number of variables
  • Switch from Get-WmiObject to Get-CimInstance
  • Convert to a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment