In this mini-series we illustrate how you can automate the process of looking up vendor information. While this mini-series focuses on Lenovo and returns the current BIOS update URI for selected models, many of the techniques illustrated here can be reused in similar scenarios as well.

In part 2 we illustrate how you can use Out-GridView as a universal dialog yet exclude unwanted properties from displaying.

Here is the script from part 1, and when you run it, a grid view window shows all Lenovo notebook model names – among a number of additional columns that may confuse the user:

# Lenovo information:
$Uri = 'https://download.lenovo.com/cdrt/td/catalogv2.xml'
# load as text:
$data = Invoke-RestMethod -Uri $Uri -UseBasicParsing
# remove first 3 bytes, convert rest to XML:
[xml]$realData = $data.Substring(3)

# choose Lenovo model
$model = $realData.ModelList.Model | Out-GridView -Title 'Choose Model' -OutputMode Single

# determine URL for BIOS download:
$result = [PSCustomObject]@{
  Model = $model.Name
  DownloadBIOS = $model.BIOS.'#text'
 
}

$result

With a clever trick you can tell PowerShell that you want Out-GridView to show only certain columns. Here is the adjusted script that displays a selection dialog with only the notebook type names:

# Lenovo information:
$Uri = 'https://download.lenovo.com/cdrt/td/catalogv2.xml'
# load as text:
$data = Invoke-RestMethod -Uri $Uri -UseBasicParsing
# remove first 3 bytes, convert rest to XML:
[xml]$realData = $data.Substring(3)

##############################NEW############################################
# create object that tells PowerShell which column(s) should be visible:
[string[]]$visible = 'Name'
$type = 'DefaultDisplayPropertySet'
[System.Management.Automation.PSMemberInfo[]]$info =
[System.Management.Automation.PSPropertySet]::new($type,$visible)

# choose Lenovo model
# to have Out-GridView show only the columns you defined in $info, add this object to
# the output before you pipe it to Out-GridView:
$model = $realData.ModelList.Model | 
    Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $info -PassThru |
    Out-GridView -Title 'Choose Model' -OutputMode Single
#
#############################################################################

# determine URL for BIOS download:
$result = [PSCustomObject]@{
  Model = $model.Name
  DownloadBIOS = $model.BIOS.'#text'
 
}

$result

We’ll focus on the technique used here in a subsequent tip.




Twitter This Tip! ReTweet this Tip!

Anonymous