PoshCode Archive  Artifact [614d63c32a]

Artifact 614d63c32a6b76991bda31140cc6695d1920fbc674be25daf18d87431b85b6a4:

  • File Instances.ps1 — part of check-in [7d0bbaa04c] at 2018-06-10 13:47:21 on branch trunk — From gregs repository on github. Plugin for wmiexplorer (copy this file into “Plugins” folder in $PSScriptRoot directory) (user: Janny size: 2304)

# encoding: ascii
# api: xml
# title: Instances
# description: From gregs repository on github. Plugin for wmiexplorer (copy this file into “Plugins” folder in $PSScriptRoot directory)
# version: 1.01
# author: Janny
# license: CC0
# x-poshcode-id: 4877
# x-archived: 2014-02-07T23:47:32
# x-published: 2014-02-04T14:00:00
#
#
<?xml version="1.0"?>
<WmiExplorerPlugin>
  <PluginAuthor>greg zakharov</PluginAuthor>
  <PluginVersion>1.01</PluginVersion>
  <InjectObject>$mnuInst</InjectObject>
  <ObjectText>&amp;Show Instances</ObjectText>
  <Code>
    if (Get-UserStatus) {
      $frmInst = New-Object Windows.Forms.Form
      $rtbInst = New-Object Windows.Forms.RichTextBox
      #
      #rtbInst
      #
      $rtbInst.Dock = [Windows.Forms.DockStyle]::Fill
      $rtbInst.ReadOnly = $true
      #
      #frmInst
      #
      $frmInst.ClientSize = New-Object Drawing.Size(530, 270)
      $frmInst.Controls.Add($rtbInst)
      $frmInst.Icon = $ico
      $frmInst.StartPosition = [Windows.Forms.FormStartPosition]::CenterParent
      $frmInst.Text = "Instances"
      $frmInst.Add_Load({
        try {
          $ins = $wmi.GetInstances()
          
          if ($ins.Count -ne 0) {
            foreach ($i in $ins) {
              $i.PSBase.Properties | % {
                $rtbInst.SelectionFont = $bol2
                $rtbInst.AppendText($_.Name + ': ')
                $rtbInst.SelectionFont = $norm
                
                if ($_.Value -eq $null) {
                  $rtbInst.AppendText("`n")
                }
                elseif ($_.IsArray) {
                  $ofs = ";"
                  $rtbInst.AppendText("$($_.Value)")
                  $ofs = $null
                  $rtbInst.AppendText("`n")
                }
                else {
                  $rtbInst.AppendText("$($_.Value)`n")
                }
              }
              $rtbInst.AppendText("`n$('=' * 57)`n")
            }
          } #if
          else {
            $rtbInst.SelectionFont = $bol1
            $rtbInst.AppendText("Out of context.")
          }
        }
        catch [Management.Automation.RuntimeException] {}
      }) #form load
      
      [void]$frmInst.ShowDialog()
    }
  </Code>
</WmiExplorerPlugin>