Gwith

update

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