Machine Info / Lookup

Modified my get-serial function to get some more stuff. Added cmdlet bindings and info for get-help

function Get-SystemInfo

{

   [CmdletBinding()]

   Param(

       [parameter(Mandatory = $true)]

       [string] $ComputerName=$(throw '$ComputerName is required'),

       [parameter(Mandatory = $true)]

       [System.Management.Automation.PSCredential] $Credential =$(Get-Credential)    )

   $bios = Get-WMIObject -Class "Win32_BIOS" -Computer $ComputerName -Credential $Credential

   $system = get-wmiobject -Class "win32_computersystem" -Computer $ComputerName -Credential $Credential

   $Enclosure = Get-WMIObject -Class "win32_SystemEnclosure" -Computer $ComputerName -Credential $Credential

   $Procs = get-wmiobject -class "Win32_Processor" -namespace "root\CIMV2" -computername $ComputerName -Credential $Credential

   $ADobject = Get-QADComputer -name $ComputerName -Credential $Credential

   #Write-Host $ComputerName", " $system.Manufacturer", " $system.Model", " $bios.SerialNumber

   Write-Host "Machine Name:  " $ComputerName

   Write-host "Manufacturer:  " $system.Manufacturer

   write-host "Model:         " $system.Model

   Write-host "Serial Number: " $bios.SerialNumber

   Write-Host "Asset Tag:     " $Enclosure.SMBIOSAssetTag

   Write-Host "OS:            " $ADobject.operatingsystem

   Write-Host "Service Pack:  " $ADobject.operatingsystemservicepack

   write-host "Memory(MB):    " $($system.TotalPhysicalMemory/1mb).tostring("N0")

   Write-Host "************Processor Informations************"

   write-host "# of Procs:    " $system.NumberOfProcessors

   foreach ($objItem in $Procs) {

       write-host "Caption: " $objItem.Caption

       write-host "CPU Status: " $objItem.CpuStatus

       write-host "Current Clock Speed: " $objItem.CurrentClockSpeed

       write-host "Device ID: " $objItem.DeviceID

       write-host "L2 Cache Size: ” $objItem.L2CacheSize

       write-host "L2 Cache Speed: " $objItem.L2CacheSpeed

       write-host "Name: " $objItem.Name

       write-host

   }

  

<#   

.synopsis

   Get information about the specified machine

.description

   Get information about the specified machine

   Pulls data from the BIOS and Active Directory

.PARAMETER Credential

   Specify a Credential variable $cred

   $cred = get-credential

.PARAMETER ComputerName

   Specify the machine you want to query for information.

.example

   Get-SystemInfo -ComputerName server01 -Credential $cred

.example

   Get-SystemInfo server01 $cred

.Link

   http://www.google.com

#>

}

  Very nice script by Don Jones

You can pipeline data into this script. 

# blog: http://windowsitpro.com/go/DonJonesPowerShell

# twitter: @concentrateddon

function Get-Inventory {

   BEGIN {

       del c:\errors.txt -erroraction 'silentlycontinue'

   }

   PROCESS {

       $computername = $_

       try {

           $os = gwmi win32_operatingsystem -comp $computername -ea 'stop'

           $bios = gwmi win32_bios -comp $computername -ea 'stop'

       } catch {

           $computername | out-file c:\errors.txt -append

       }

       $obj = new-object psobject

       $obj | add-member noteproperty ComputerName ($computername)

       $obj | add-member noteproperty OSVersion ($os.caption)

       $obj | add-member noteproperty SPVersion ($os.servicepackmajorversion)

       $obj | add-member noteproperty BIOSSerial ($bios.serialnumber)

       $obj | add-member noteproperty OSBuild ($os.buildnumber)

       write-output $obj

   }

}

get-content c:\computers.txt | get-inventory | convertto-html | out-file c:\inventory.html 

Computer Lookup

Lookup a computer name and return the description

$ImportFile="H:\scripts\PowerShell\MachineLookup\machines_with_blah.csv"

$ExportFile="H:\scripts\PowerShell\MachineLookup\machines_with_blah_Updated.csv"

$Machines =Import-Csv $ImportFile

foreach ($machine in $machines) {

$computer = Get-QADComputer -Name $Machine.Computer

$machine | Add-Member -membertype noteproperty -name Description -Value $($computer.Description)

}

$Machines | Export-Csv -NoTypeInformation $ExportFile 

 

$importfile= 'C:\input.csv'

$exportfile= 'C:\output.csv'

$List = Import-Csv $importfile

foreach ($computer in $List) 

{

    $ADComputer = Get-QADComputer  -LdapFilter "(Name=$($computer.machine))"

    Write-Host "looking for " ($computer.machine) " in AD Found " $($ADComputer.Name)

    $computer | Add-Member -membertype noteproperty -name OS -Value $($ADComputer.operatingSystem)

    $computer | Add-Member -membertype noteproperty -name SP -Value $($ADComputer.operatingSystemServicePack)

    $computer | Add-Member -membertype noteproperty -name whenCreated -Value $($ADComputer.whenCreated)

    $computer | Add-Member -membertype noteproperty -name whenChanged -Value $($ADComputer.whenChanged)

}

$list | Export-Csv -NoTypeInformation $exportfile