Gwith

update

May 23rd, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. function Get-Info {
  2. [cmdletbinding()]
  3. param([parameter(
  4. Mandatory=$True,
  5. ValueFromPipeline=$true,
  6. ValueFromPipelineByPropertyName=$true
  7. )]
  8. [alias('hostname')]
  9. [string[]]$ComputerName
  10. )
  11.  
  12. BEGIN{
  13. }
  14.  
  15. PROCESS{
  16.  
  17. foreach ($Computer in $ComputerName) {
  18. #only scan WMI if the computer responds to ping
  19. Write-Verbose "Pinging $computer"
  20. if(test-connection -ComputerName $computer -Count 1 -Quiet){
  21. Write-Verbose "$Computer responded to ping"
  22. try
  23. {
  24. $CS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer -ErrorAction Stop
  25. $BS = Get-WmiObject -Class Win32_Bios -ComputerName $Computer -ErrorAction Stop
  26. $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop
  27. }
  28. catch
  29. {
  30.  
  31. "$(get-date) - $computer failed the wmi call!" | out-file c:\errorlog.txt -Append
  32. $error[0].Exception.Message | out-file c:\errorlog.txt -Append
  33. }
  34.  
  35. Write-Verbose "Switchy switches!"
  36. switch ($CS.AdminPasswordStatus)
  37. {
  38. '0' {$AdminPasswordStatus = "Not set" }
  39. '1' {$AdminPasswordStatus = "Disabled"}
  40. '2' {$AdminPasswordStatus = "Enabled"}
  41. '3' {$AdminPasswordStatus = "N/A"}
  42. '4' {$AdminPasswordStatus = "Unknown"}
  43. Default {$AdminPasswordStatus = "FAIL!"}
  44. }
  45.  
  46. switch -Wildcard ($OS.Version)
  47. {
  48. '6.1.7600' {$OS.Version = "7"}
  49. '6.1.7601' {$OS.Version = "7 SP1"}
  50. '*9200*' {$OS.Version = "8/2012"}
  51. '*9600*' {$OS.Version = "8.1/2012R2"}
  52. Default {$OS.Version = "OLD!"}
  53. }
  54.  
  55.  
  56. #create new object for current computer
  57. $thiscomputerobj = [pscustomobject][ordered]@{
  58. ComputerName = $Computer.toupper();
  59. Domain = $CS.Domain;
  60. AdminPW = $AdminPasswordStatus;
  61. Model = $CS.Model;
  62. Manufacturer = $CS.Manufacturer;
  63. SerialNumber = $BS.SerialNumber;
  64. Version = $OS.Version;
  65. #ServicePack = $OS.ServicePackMajorVersion
  66. }
  67.  
  68.  
  69.  
  70. }#end test-connection if
  71.  
  72. }#end foreach
  73.  
  74. }#end Process
  75.  
  76.  
  77. End{
  78. Write-Verbose 'End'
  79. $thiscomputerobj
  80. }
  81.  
  82. }#end function
  83.  
  84. Get-Info
Advertisement
Add Comment
Please, Sign In to add comment