Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- 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.
- Design a command that will retrieve the following information from one or more remote computers, using the indicated WMI classes and properties:
- Win32_ComputerSystem:
- o Workgroup
- o AdminPasswordStatus; display the numeric values of this property as text strings.
- For 1, display Disabled
- For 2, display Enabled
- For 3, display NA
- For 4, display Unknown
- o Model
- o Manufacturer
- From Win32_BIOS
- o SerialNumber
- From Win32_OperatingSystem
- o Version
- o ServicePackMajorVersion
- Your function’s output should also include each computer’s name.
- 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:
- • ComputerName
- • Workgroup
- • AdminPassword (for AdminPasswordStatus in Win32_ComputerSystem)
- • Model
- • Manufacturer
- • BIOSSerial (for SerialNumber in Win32_BIOS)
- • OSVersion (for Version in Win32_OperatingSystem)
- • SPVersion (for ServicePackMajorVersion in Win32_OperatingSystem)
- Again, you aren’t writing the script only outlining what you might do..
- #>
- Function Get-SystemInfo {
- param(
- [string]$ComputerName = 'localhost'
- )
- $Error = 'C:\Scripts\Errors.txt'
- $AdminPasswordStatus = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $ComputerName | Format-Table -Property AdminPasswordStatus
- Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName localhost | Format-Table @{L='AdminPassword';E={$_.AdminPasswordStatus}}
- Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName | Select-Object -Property Version, ServicePackMajorVersion | Format-Table -Property OSVersion, SPVersion
- Get-CimInstance -ClassName Win32_BIOS -ComputerName $ComputerName | Select-Object -Property SerialNumber
- Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName | Select-Object -Property Version, ServicePackMajorVersion
- if ($AdminPasswordStatus -eq 1)
- {
- write-host "AdminPasswordStatus: Disabled"
- }
- Elseif ($AdminPassWordStatus -eq 2)
- {
- Write-Host "AdminPasswordStatus: Enabled"
- }
- Elseif ($AdminPassWordStatus -eq 3)
- {
- Write-Host "AdminPasswordStatus: Disabled"
- }
- Else
- {
- Write-Host "AdminPasswordStatus: Unknown"
- }
- }
- Get-SystemInfo
Advertisement
Add Comment
Please, Sign In to add comment