Showing posts with label win32_computersystem. Show all posts
Showing posts with label win32_computersystem. Show all posts

Tuesday, 4 January 2011

Get-ComputerDomain.ps1

<#
.SYNOPSIS
This script uses WMI to get the name of a computer's domain then displays the name.
.DESCRIPTION
This script is a re-write of an MSDN sample, using PowerShell.
.NOTES
File Name : Get-ComputerDomain.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted tot:
http://msdn.microsoft.com/en-us/library/aa394586%28VS.85%29.aspx/
.EXAMPLE
PSH [C:\foo]: .\Get-ComputerDomain.ps1
System Name: WIN7
Domain: cookham.net
.EXAMPLE
Psh[Cookham8]> .\Get-ComputerDomain.ps1 cookham2
System Name: COOKHAM2
Domain: cookham.net
.PARAMETER comp
The name of the computer whose domain name to be displayed. Default is localhost.
#>


# Parameter block
param (
$comp = "."
)

# Get WMI Object
$system = Get-WmiObject -class Win32_ComputerSystem -ComputerName $comp

# Display results
"System Name: {0}" -f $System.Name
"Domain: {0}" -f $System.Domain


Tuesday, 17 August 2010

Get-BrokenHardware.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets a list of non-working hardware using WMI. 
  4. .DESCRIPTION 
  5.     This script re-implements another TechNet Scripting 
  6.     Gallery script that was written in VB (see  
  7.     http://tinyurl.com/y4hmtbr).  
  8.     This script first uses WMI to get system details, then 
  9.     gets and displays hardware that has errored. 
  10. .NOTES 
  11.     File Name  : Get-BrokenHardware.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     This script posted to TechNet Script Gallery at: 
  18.         http://gallery.technet.microsoft.com/ScriptCenter/en-us/dbb678f4-b95b-45c3-bc8b-2ae2d052448e     
  19. .EXAMPLE 
  20.     PSH [C:\foo]: Get-BrokenHardware.ps1 
  21.     Computer Details: 
  22.     Manufacturer: Dell Inc. 
  23.     Model:        Precision WorkStation T7400 
  24.     Service Tag:  6Y84C3J 
  25.  
  26.     Hardware that's not working list 
  27.     Description:  WD My Book Device USB Device 
  28.     Device ID:    USBSTOR\OTHER&VEN_WD&PROD_MY_BOOK_DEVICE&REV_1010\7&2A4E07C&0&575532513130303732383932&1 
  29.     Error ID:     28 
  30. #> 
  31.  
  32. # Display Computer details 
  33. "Computer Details:" 
  34. $comp = gwmi Win32_ComputerSystem 
  35. "Manufacturer: {0}" -f $comp.Manufacturer 
  36. "Model:        {0}" -f $comp.Model 
  37. $computer2 = Get-WmiObject Win32_ComputerSystemProduct 
  38. "Service Tag:  {0}" -f $computer2.IdentifyingNumber 
  39. "" 
  40.  
  41. #Get hardware that is errored 
  42. "Hardware that's not working list"  
  43. $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0} 
  44.  
  45. #Display broken hardware 
  46. foreach ($obj in $broken){   
  47. "Description:  {0}" -f  $obj.Description 
  48. "Device ID:    {0}" -f  $obj.DeviceID 
  49. "Error ID:     {0}" -f  $obj.ConfigManagerErrorCode 
  50. "" 
  51. } 

Tuesday, 13 January 2009

Get-UpTime.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates uptime using WMI  
  4. .DESCRIPTION 
  5.     This script used Win32_ComputerSystem to determine how long your system 
  6.     has been running. This is a rewrite/improvement of sample 3 at 
  7.     http://msdn.microsoft.com/en-us/library/aa394591(VS.85).aspx.  
  8. .NOTES 
  9.     File Name : Get-UpTime.ps1 
  10.     Author : Thomas Lee - tfl@psp.co.uk 
  11.     Requires : PowerShell V2 CTP3 
  12. .LINK 
  13.     Script Posted to:  
  14.     http://www.pshscripts.blogspot.com 
  15.     Original sample posted at: 
  16.     http://msdn.microsoft.com/en-us/library/aa394591(VS.85).aspx 
  17. .EXAMPLE 
  18.     PS c:\foo> .\Get-UpTime.Ps1 
  19.     System Up for: 1 days, 8 hours, 40.781 minutes 
  20.  
  21. #> 
  22.  
  23. ## 
  24. #  Start of script 
  25. ## 
  26.  
  27. # Helper Function - convert WMI date to TimeDate object 
  28. function WMIDateStringToDate($Bootup) { 
  29.     [System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup) 
  30. } 
  31.  
  32. # Main script 
  33. $Computer = "." # adjust as needed 
  34. $computers = Get-WMIObject -class Win32_OperatingSystem -computer $computer 
  35.  
  36. foreach ($system in $computers) { 
  37.     $Bootup = $system.LastBootUpTime 
  38.     $LastBootUpTime = WMIDateStringToDate($Bootup) 
  39.     $now = Get-Date 
  40.     $Uptime = $now - $lastBootUpTime 
  41.     $d = $Uptime.Days 
  42.     $h = $Uptime.Hours 
  43.     $m = $uptime.Minutes 
  44.     $ms= $uptime.Milliseconds 
  45.     "System Up for: {0} days, {1} hours, {2}.{3} minutes" -f $d,$h,$m,$ms 
  46. }  
  47. # End script 

Tuesday, 2 December 2008

Get-PhysicalRam.ps1


# Get-PhysicalRAM.ps1
#
Sample using PowerShell
#
3rd sample from http://msdn.microsoft.com/en-us/library/aa394587
#
Thomas Lee

$mem = Get-WmiObject -Class Win32_ComputerSystem

# Display memory
"This system has {0} MB Free Memory" -f $($mem.TotalPhysicalMemory/1mb)
This script produces the following output:



PS C:\foo> .\Get-PhysicalRAM
This system has 8188.7421875 MB Free Memory