locked
Powershell to pull on specific bios versions RRS feed

  • Question

  • Hello Scripting Guy

    I have a powershell script that goes through the Domain OU's and list all bios versions of the systems and exports this to and excel spreadsheet.

    I am now trying to get this to only get specific bios version of these system and put that information into a spreadsheet.

    I works to a point as it list the systems with the specific bios version but also list all other system that do not have this specific bios version.

    I have this

    $

    $Bios=Get-WmiObject-classWin32_BIOS-computer$pcname|where-object{
    $_.SMBIOSBIOSVERSION
    -like"*FBKTCL*"}
    
    
    $DeviceInfo.add("Bios
     Version",$Bios.SMBIOSBIOSVersion)
    
    
    $out+=New-ObjectPSObject-Property$DeviceInfo|Select-Object
    
    
    
    "System Name","Operating
     System","Manufacturer","Model","Bios
     Version","Last
     Logged In" 
    
    $out|Export-CSV$outfile-NoTypeInformation

    Can you help on this.

    Thanks

    Dave



    • Edited by dedwards99 Wednesday, February 7, 2018 8:31 PM
    Wednesday, February 7, 2018 8:12 PM

Answers

  • ([adsisearcher]'(objectCategory=computer)').FindAll() |
    ForEach-Object{
        $pcname = $_.Properties['name']
        if ($connection = Test-Connection $_ -Count 1 -Quiet) {
            if ($Bios = Get-WmiObject -class Win32_BIOS -ComputerName $pcname -Filter 'SMBIOSBIOSVERSION like "%FBKTCL%"') {
                $os = Get-WmiObject -class win32_operatingsystem -ComputerName $pcname
                $comp = Get-WmiObject -class win32_computersystem -ComputerName $pcname
                $java = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'name like "%java%"'
                $vol = Get-WmiObject -class Win32_Volume -ComputerName $pcname
                $net = Get-WmiObject -class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=True' -ComputerName $pcname
                $CB = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'Name like "%CB%"'
                $Proc = Get-Wmiobject -class Win32_processor -ComputerName $pcname
                
                [pscustomobject]@{
                    'Operating System'    = $os.name.split('|')[0]
                    'Version'             = $os.Version
                    'Architecture'        = $os.OSArchitecture
                    'Serial Number'       = $Bios.SerialNumber
                    'Manufacturer'        = $Bios.Manufacturer
                    'Bios Version'        = $Bios.SMBIOSBIOSVersion
                    'System Name'         = $comp.Name
                    'Model'               = $comp.Model
                    'Processor'           = $Proc.Name
                    'Last Logged In'      = $comp.UserName
                    'Java Version'        = $java.name -join ' = '
                    'File System'         = $vol.FileSystem
                    'IP Address'          = $net.IPAddress -join ' = '
                    'Subnet'              = $net.IPSubnet -join ' = '
                    'MAC Address'         = $net.MACAddress
                    'Carbon Black'        = $CB.name -join ' = '
                    'Carbon Black Vendor' = $CB.Vendor -join ' = '
                    'Carbon Black Version' = $CB.Version -join ' = '
                }
            }
        }
    }
    


    \_(ツ)_/

    • Marked as answer by dedwards99 Thursday, February 8, 2018 3:35 PM
    Thursday, February 8, 2018 12:03 AM

All replies

  • Please do not post formatted/colorized code.   Use the provided code posting tool <>.

    You code cannot be easily read and it cannot be copied without errors.


    \_(ツ)_/

    Wednesday, February 7, 2018 8:17 PM
  • Sorry did not know about this.

    Hope it is ok now.

    Wednesday, February 7, 2018 8:31 PM
  • Better but the formatting is still bad.  The code, as posted, cannot possible run.  This makes it impossible to understand your question.

    You are asking for on BIOs from one PC.  The result can be blank.  YOU have an object that you are adding to something and then creating a new object.  None of that makes much sense.


    \_(ツ)_/

    Wednesday, February 7, 2018 8:34 PM
  • If you want to go thru the list of computers, you will have to wrap this into foreach loop, where you would check every single computer which you have in some file, or in a collection.

    Something like this:

    $collection = New-Object PSObject
    
    foreach ($pc in $pcname)
    {
        $Bios=Get-WmiObject -class Win32_BIOS -computer $pc | where-object{ $_.SMBIOSBIOSVERSION -like "*FBKTCL*"}
    
        if (!([string]::IsNullOrEmpty($bios.SMBIOSBIOSVersion)))
        {
            $collection | Add-Member -MemberType NoteProperty -Name 'System Name' -Value $bios.PSComputerName
            $collection | Add-Member -MemberType NoteProperty -Name 'manufacturer' -Value $bios.Manufacturer
            $collection | Add-Member -MemberType NoteProperty -Name 'Model' -Value $bios.Version
            $collection | Add-Member -MemberType NoteProperty -Name 'Bios Version' -Value $bios.SMBIOSBIOSVersion
        }
    }
    
    $collection | Export-CSV $outfile -NoTypeInformation


    Please click on Propose As Answer or to mark this post as and helpful for other people. This posting is provided AS-IS with no warranties, and confers no rights.


    • Edited by Vlad817263 Wednesday, February 7, 2018 8:43 PM
    Wednesday, February 7, 2018 8:43 PM
  • Here is my script that I am using.

    <# .SYNOPSIS Powershell script to get system information from remote computers. .DESCRIPTION This PowerShell script gets computer from the selected OU in the $Domain Parameter and remotely gets the system information for the DeviceInfo objects selected. The output is written to a another CSV file location as enter in the $outfile Parameter. .PARAMETER $domain System Directory Service Directory Entry "LDAP://OU=,OU=,DC=,DC=". .PARAMETER $outfile File name and path of the outout CSV file. #> # Enter where to save the output CSV file $outfile = "Location for CSV to be saved" #Domain Information OU where you want to get the PC Function Get-Pcs{ #Entered specific OU to search against on the Domain $domain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=SITENAME,OU=COMPUTERS,DC=DOMAIN,DC=local") $ds = New-Object System.DirectoryServices.DirectorySearcher $ds.SearchRoot = $domain $ds.Filter = ("(objectCategory=computer)") $rslts = $ds.FindAll() return $rslts } $HostList = Get-Pcs $out = @() foreach($object in $HostList){ $pcname = $object.Properties.name $connection = Test-Connection $object.Properties.name -Count 1 -ErrorAction SilentlyContinue if ($connection -ne $null) { $os = Get-WmiObject -class win32_operatingsystem -computer $pcname $comp = Get-WmiObject -class win32_computersystem -computer $pcname $Bios = Get-WmiObject -class Win32_BIOS -computer $pcname | where-object { $_.SMBIOSBIOSVERSION -like "*FBKTCL*" } $java = Get-WmiObject -class Win32_Product -computer $pcname | where-object { $_.name -like "*java*" } $vol = Get-WmiObject -class Win32_Volume -computer $pcname $net = Get-WmiObject -class Win32_NetworkAdapterConfiguration -computer $pcname | where-object { $_.IPAddress -ne $null } $CB = Get-WmiObject -class Win32_Product -computer $pcname | where-object { $_.name -like "*CB*" } $Proc = Get-Wmiobject -class Win32_processor -computer $pcname $DeviceInfo= @{} $DeviceInfo.add("Operating System", $os.name.split("|")[0]) $DeviceInfo.add("Version", $os.Version) $DeviceInfo.add("Architecture", $os.OSArchitecture) $DeviceInfo.add("Serial Number", $Bios.SerialNumber) $DeviceInfo.add("Manufacturer", $Bios.Manufacturer) $DeviceInfo.add("Bios Version", $Bios.SMBIOSBIOSVersion) $DeviceInfo.add("System Name", $comp.Name) $DeviceInfo.add("Model", $comp.Model) $deviceInfo.add("Processor",$Proc.Name) $DeviceInfo.add("Last Logged In", $comp.UserName) $deviceInfo.add("Java Version", ($java.name -join (", "))) $DeviceInfo.add("File System", $vol.FileSystem) $DeviceInfo.add("IP Address", ($net.IPAddress -join (", "))) $DeviceInfo.add("Subnet", ($net.IPSubnet -join (", "))) $DeviceInfo.add("MAC Address", $net.MACAddress ) $deviceInfo.add("Carbon Black", ($CB.name -join (", "))) $deviceInfo.add("Carbon Black Vendor", ($CB.Vendor -join (", "))) $deviceInfo.add("Carbon Black Version", ($CB.Version -join (", "))) $out += New-Object PSObject -Property $DeviceInfo | Select-Object "System Name","Operating System","Manufacturer","Model","Bios Version","Last Logged In" $out | Export-CSV $outfile -NoTypeInformation # This will output to xml file. #$out | Export-clixml $outfile } }


    Wednesday, February 7, 2018 9:03 PM
  • This would work better:

    ([adsisearcher]'(objectCategory=computer)').FindAll() |
    ForEach-Object{
        $pcname = $_.Properties['name']
        if ($connection = Test-Connection $_ -Count 1 -Quiet) {
            $os = Get-WmiObject -class win32_operatingsystem -ComputerName $pcname
            $comp = Get-WmiObject -class win32_computersystem -ComputerName $pcname
            $Bios = Get-WmiObject -class Win32_BIOS -ComputerName $pcname -Filter 'SMBIOSBIOSVERSION like "%FBKTCL%"'
            $java = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'name like "%java%"'
            $vol = Get-WmiObject -class Win32_Volume -ComputerName $pcname
            $net = Get-WmiObject -class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=True' -ComputerName $pcname
            $CB = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'Name like "%CB%"'
            $Proc = Get-Wmiobject -class Win32_processor -ComputerName $pcname
            
            [pscustomobject]@{
                'Operating System'   = $os.name.split('|')[0]
                'Version'            = $os.Version
                'Architecture'       = $os.OSArchitecture
                'Serial Number'      = $Bios.SerialNumber
                'Manufacturer'       = $Bios.Manufacturer
                'Bios Version'       = $Bios.SMBIOSBIOSVersion
                'System Name'        = $comp.Name
                'Model'              = $comp.Model
                'Processor'          = $Proc.Name
                'Last Logged In'     = $comp.UserName
                'Java Version'       = $java.name -join ' = '
                'File System'        = $vol.FileSystem
                'IP Address'         = $net.IPAddress -join ' = '
                'Subnet'             = $net.IPSubnet -join ' = '
                'MAC Address'        = $net.MACAddress
                'Carbon Black'       = $CB.name -join ' = '
                'Carbon Black Vendor' = $CB.Vendor -join ' = '
                'Carbon Black Version' = $CB.Version -join ' = '
            }
        }
    }
    
    


    \_(ツ)_/


    • Edited by jrv Wednesday, February 7, 2018 9:51 PM
    Wednesday, February 7, 2018 9:20 PM
  • I get this when I run your version.

    Test-Connection : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At line:52 char:39
    +     if ($connection = Test-Connection $_ -Count 1 -Quiet) {
    +                                       ~~
        + CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand

    Wednesday, February 7, 2018 9:41 PM
  • You still have to get the computernames variable first.

    This gets all computers in the domain:

    $computers = ([adsisearcher]'(objectCategory=computer)').FindAll()

    THen we modify this:

    $computers |
    ForEach-Object{
        $pcname
    =$_.Properties['name']


    \_(ツ)_/

    Wednesday, February 7, 2018 9:50 PM
  • Thanks for this but at this time I do not want to search the whole domain. I just select a small computer OU to test if the script works the way I want it.

    I use the following to do this.

    Function Get-Pcs {

    $domain = New-Object System.DirectroyServices.DirectoryEntry("LDAP://OU=Site,OU=Computers,DC=Domain,DC=Local)

    $ds = New-Object System.DirectoryServices.DirectorySearcher

    $ds.SearchRoot = $domain

    $ds.filter = ("(objectCategory=computer)")

    $rslts = $ds.FindAll()return $rslts

    }

    $hostlist = Get-Pcs

    Foreach($object in $hostlist) {

    $pcname = $object.Properties.name

    Then the rest of the code after this.

    Wednesday, February 7, 2018 10:37 PM
  • So we would just do this:

    $searcher = [adsisearcher]'(objectCategory=computer)'
    $searcher.SearchRoot = 'LDAP://OU=Site,OU=Computers,DC=Domain,DC=Local'
    $searcher.FindAll() |
    ForEach-Object{
        $pcname = $_.Properties['name']
    


    \_(ツ)_/

    Wednesday, February 7, 2018 10:55 PM
  • Ok got that not a problem.

    But my original question was now to get the system with only a specific Bios version listed and not every system.

     

    Wednesday, February 7, 2018 11:09 PM
  • Just use an "if" to test the bios version and skip all that don't have that version.


    \_(ツ)_/

    Thursday, February 8, 2018 12:01 AM
  • ([adsisearcher]'(objectCategory=computer)').FindAll() |
    ForEach-Object{
        $pcname = $_.Properties['name']
        if ($connection = Test-Connection $_ -Count 1 -Quiet) {
            if ($Bios = Get-WmiObject -class Win32_BIOS -ComputerName $pcname -Filter 'SMBIOSBIOSVERSION like "%FBKTCL%"') {
                $os = Get-WmiObject -class win32_operatingsystem -ComputerName $pcname
                $comp = Get-WmiObject -class win32_computersystem -ComputerName $pcname
                $java = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'name like "%java%"'
                $vol = Get-WmiObject -class Win32_Volume -ComputerName $pcname
                $net = Get-WmiObject -class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=True' -ComputerName $pcname
                $CB = Get-WmiObject -class Win32_Product -ComputerName $pcname -Filter 'Name like "%CB%"'
                $Proc = Get-Wmiobject -class Win32_processor -ComputerName $pcname
                
                [pscustomobject]@{
                    'Operating System'    = $os.name.split('|')[0]
                    'Version'             = $os.Version
                    'Architecture'        = $os.OSArchitecture
                    'Serial Number'       = $Bios.SerialNumber
                    'Manufacturer'        = $Bios.Manufacturer
                    'Bios Version'        = $Bios.SMBIOSBIOSVersion
                    'System Name'         = $comp.Name
                    'Model'               = $comp.Model
                    'Processor'           = $Proc.Name
                    'Last Logged In'      = $comp.UserName
                    'Java Version'        = $java.name -join ' = '
                    'File System'         = $vol.FileSystem
                    'IP Address'          = $net.IPAddress -join ' = '
                    'Subnet'              = $net.IPSubnet -join ' = '
                    'MAC Address'         = $net.MACAddress
                    'Carbon Black'        = $CB.name -join ' = '
                    'Carbon Black Vendor' = $CB.Vendor -join ' = '
                    'Carbon Black Version' = $CB.Version -join ' = '
                }
            }
        }
    }
    


    \_(ツ)_/

    • Marked as answer by dedwards99 Thursday, February 8, 2018 3:35 PM
    Thursday, February 8, 2018 12:03 AM
  • Hello

    thank you for the help on this.

    The IF statement worked and it now only get the systems with the specific bios version.

    Have a great day

    Thursday, February 8, 2018 3:36 PM