myITforum and Windows IT Pro Forums

 1st real PowerShell script - and 1st real problem

Author Message
msutliff

  • Total Posts : 196
  • Scores: 2
  • Reward points : 29940
  • Joined: 7/31/2003
  • Location: Oklahoma
  • Status: offline
1st real PowerShell script - and 1st real problem Monday, February 03, 2014 12:39 PM (permalink)
0
Hello everyone,
Here is something I’m trying to do that I can’t seem to work out.
I’m wanting to display properties from WMI using the OUT-GRIDVIEW.
For instance:
$CompSys = Get-WmiObject win32_computersystem|Select-Object Name,Model,Manufacturer,TotalPhysicalMemory,UserName
$BIOS = get-wmiobject win32_bios | select-object SMBIOSBIOSVersion,serialnumber
$OpSys = get-wmiobject win32_operatingsystem|select-object Caption,Version,Buildnumber,CSDVersion,SystemDrive,SystemDirectory,LastBootUpTime,LocalDateTime,InstallDate,TotalVisibleMemorySize,OSLanguage,MUILanguages
$OS_Class = Get-WmiObject -Class Win32_OperatingSystem
$PhyMem = get-wmiobject win32_physicalmemory |select-object DeviceLocator,Capacity,Speed,Type
$NetIP = get-wmiobject win32_networkadapterconfiguration | where {$_.IPAddress}|select-object Description,DHCPServer,DNSDomain,DNSDomainSuffixSearchOrder,DNSServerSearchOrder,IPAddress,DefaultIPGateway,IPSubnet,MACAddress
$ImgVer = get-itemproperty -path HKLM:\System\Setup|select-object imageversion
 
I can then set a text field on a form, such as $label4.text = $OpSys.Caption
But how do I add all this, I presume, to an array then pass that to output like array$ | out-gridview
I’ve tried for a few days to get this to work and I’m not figuring it out.  J
Thanks for shining the way!
 
 
#1
    akaplan

    • Total Posts : 146
    • Scores: 38
    • Reward points : 21130
    • Joined: 4/22/2003
    • Location: North Carolina
    • Status: offline
    Re:1st real PowerShell script - and 1st real problem Monday, February 03, 2014 1:22 PM (permalink)
    0
    Try using a .NET datatable, or PSCustomObject.

    Alan Kaplan --- www.akaplan.com/blog
     
    #2
      curtmcgirt

      • Total Posts : 1
      • Scores: 0
      • Reward points : 260
      • Joined: 2/4/2014
      • Status: offline
      Re:1st real PowerShell script - and 1st real problem Tuesday, February 04, 2014 12:22 AM (permalink)
      0
      so you want to have $compsys and $bios in the same gridview? or you want each of those items to be in its own gridview? what would the column headings be if $compsys has six columns, and $bios hash two columns?
       
      #3
        msutliff

        • Total Posts : 196
        • Scores: 2
        • Reward points : 29940
        • Joined: 7/31/2003
        • Location: Oklahoma
        • Status: offline
        Re:1st real PowerShell script - and 1st real problem Tuesday, February 04, 2014 10:36 AM (permalink)
        0
        Sorry for leaving out the details.
        Yes, looking at basically two columns, Name & Value and all these results in one grid view.  So...
        <start of big grid>
        computersystem.name, value
        computersystem.manu, value
        bios.version, value
        bios.serialnumber,value
        operatingsystem.caption,value
        blah.value
        blah.value
        blah.value
        <end of big grid>
         
        AKAPLAN has me studying CustomObject, I just need to figure out how to put it together :-)  Office is quiet today, maybe I can figure it out.
         
         
        #4
          msutliff

          • Total Posts : 196
          • Scores: 2
          • Reward points : 29940
          • Joined: 7/31/2003
          • Location: Oklahoma
          • Status: offline
          Re:1st real PowerShell script - and 1st real problem Tuesday, February 04, 2014 10:36 AM (permalink)
          0
          I figured it out.  The book I was using was PowerShell 2.  Hashtables were mentioned..
          I found a PowerShell 3 book and read more about Hashtables and how I can use [ordered] when creating it.
          Problem solved after spending an afternoon downloading/installing .NET 4.5.1 and Windows Framework..
           
          $result = [Ordered] @{
               "Name" = $CompSys.Name;
               "BIOS Ver" = $BIOS.SMBIOSBIOSVersion;
               "Version" = $OpSys.Version;
          }
          out-gridview -inputobject $result -Title "Sheldon's fun with WMI"
           
          <message edited by msutliff on Wednesday, February 05, 2014 1:14 PM>
           
          #5
            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 2 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2014 ASPPlayground.NET Forum Version 3.9