Gwith

Lab

May 21st, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1.  
  2. function Get-Info {
  3. [cmdletbinding()]
  4. param(
  5. [parameter(Mandatory)]
  6. [alias('hostname')]
  7. [string[]]$ComputerName
  8. )
  9.  
  10. BEGIN{
  11. Write-Verbose 'Begin'
  12. }
  13.  
  14. PROCESS{
  15. Write-Verbose 'Process'
  16. foreach ($Computer in $ComputerName) {
  17. try{
  18. Write-Verbose 'Continue or not to Continue'
  19. $Continue = $true
  20. $AdminPasswordStatus = Get-WmiObject -EV myerr1 -EA stop -Class Win32_ComputerSystem -ComputerName $ComputerName `
  21. `
  22. | Select-Object -ExpandProperty AdminPasswordStatus
  23.  
  24. $CS = Get-WmiObject -EV myerr2 -EA stop -Class Win32_ComputerSystem -ComputerName $ComputerName `
  25. `
  26. | Select-Object -Property Domain,Model,Manufacturer
  27.  
  28. $BS = Get-WmiObject -EV myerr3 -EA stop -Class Win32_Bios -ComputerName $ComputerName `
  29. `
  30. | Select-Object -property SerialNumber
  31.  
  32. $OS = Get-WmiObject -EV myerr4 -EA stop -Class Win32_OperatingSystem -ComputerName $ComputerName `
  33. `
  34. | Select-Object -Property Version,ServicePackMajorVersion
  35. } catch {
  36. Write-Verbose 'Catch'
  37. $Continue = $false
  38. $Computer = Out-File C:\errorlog.txt
  39. $myerr1 | Out-File C:\errormessages.txt -Append
  40. $myerr2 | Out-File C:\errormessages.txt -Append
  41. $myerr3 | Out-File C:\errormessages.txt -Append
  42. $myerr4 | Out-File C:\errormessages.txt -Append
  43. }
  44.  
  45. if ($Continue = $true) {
  46. Write-Verbose 'Pass thru if the if fits'
  47. switch ($AdminPasswordStatus)
  48. {
  49. '1' {$AdminPasswordStatus = "Disabled"}
  50. '2' {$AdminPasswordStatus = "Enabled"}
  51. '3' {$AdminPasswordStatus = "NA"}
  52. '4' {$AdminPasswordStatus = "Unknown"}
  53. Default {"Sorry"}
  54. }
  55.  
  56. $obj = [pscustomObject] @{
  57. ComputerName = $ComputerName;
  58. Domain = $CS.Domain;
  59. AdminPW = $AdminPasswordStatus
  60. Model = $cs.Model;
  61. Manufacturer = $CS.Maanufacturer;
  62. SerialNumber = $BS.SerialNumber;
  63. Version = $OS.Version;
  64. ServicePack = $OS.ServicePackMajorVersion}
  65. }
  66. }
  67. }
  68.  
  69. End{
  70. Write-Verbose 'End'
  71. $obj
  72. }
  73. }
  74.  
  75.  
  76.  
  77.  
  78. Get-Info -ComputerName localhost, noton -Verbose
Advertisement
Add Comment
Please, Sign In to add comment