Gwith

Lab6

May 20th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <#
  2. In this lab, we aren’t going to have you write any actual scripts or functions. Instead, we want you to think about the design aspect, something many people overlook. Let’s say you’ve been asked to develop the following PowerShell tools. Even though the tool will be running from PowerShell 3.0, you don’t have to assume that any remote computer is running PowerShell 3.0. Assume at least PowerShell v2.
  3.  
  4. Design a command that will retrieve the following information from one or more remote computers, using the indicated WMI classes and properties:
  5.  Win32_ComputerSystem:
  6. o Workgroup
  7. o AdminPasswordStatus; display the numeric values of this property as text strings.
  8.  For 1, display Disabled
  9.  For 2, display Enabled
  10.  For 3, display NA
  11.  For 4, display Unknown
  12. o Model
  13. o Manufacturer
  14.  From Win32_BIOS
  15. o SerialNumber
  16.  From Win32_OperatingSystem
  17. o Version
  18. o ServicePackMajorVersion
  19.  
  20. Your function’s output should also include each computer’s name.
  21. Ensure that your function’s design includes a way to log errors to a text file, allowing the user to specify an error file name but defaulting to C:\Errors.txt. Also plan ahead to create a custom view so that your function always outputs a table, using the following column headers:
  22. • ComputerName
  23. • Workgroup
  24. • AdminPassword (for AdminPasswordStatus in Win32_ComputerSystem)
  25. • Model
  26. • Manufacturer
  27. • BIOSSerial (for SerialNumber in Win32_BIOS)
  28. • OSVersion (for Version in Win32_OperatingSystem)
  29. • SPVersion (for ServicePackMajorVersion in Win32_OperatingSystem)
  30. Again, you aren’t writing the script only outlining what you might do..
  31. #>
  32.  
  33. function Get-Info {
  34. param(
  35. [parameter(Mandatory)]
  36. [alias('hostname')]
  37. [string]$ComputerName
  38. )
  39.  
  40. BEGIN{
  41.  
  42. }
  43.  
  44. PROCESS{
  45. $AdminPasswordStatus = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName | Select-Object -ExpandProperty AdminPasswordStatus
  46. $CS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName | Select-Object -Property Domain,Model,Manufacturer
  47. $BS = Get-WmiObject -Class Win32_Bios -ComputerName $ComputerName | Select-Object -property SerialNumber
  48. $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName | Select-Object -Property Version,ServicePackMajorVersion
  49. switch ($AdminPasswordStatus)
  50. {
  51. '1' {$AdminPasswordStatus = "Disabled"}
  52. '2' {$AdminPasswordStatus = "Enabled"}
  53. '3' {$AdminPasswordStatus = "NA"}
  54. '4' {$AdminPasswordStatus = "Unknown"}
  55. Default {"Sorry"}
  56. }
  57.  
  58. $obj = [pscustomObject] @{
  59. ComputerName = $ComputerName;
  60. Domain = $CS.Domain;
  61. AdminPW = $AdminPasswordStatus
  62. Model = $cs.Model;
  63. Manufacturer = $CS.Maanufacturer;
  64. SerialNumber = $BS.SerialNumber;
  65. Version = $OS.Version;
  66. ServicePack = $OS.ServicePackMajorVersion}
  67. }
  68.  
  69. End{
  70. $obj
  71. }
  72. }
  73.  
  74.  
  75.  
  76. Get-Info -ComputerName localhost
Advertisement
Add Comment
Please, Sign In to add comment