Created
September 11, 2015 22:36
-
-
Save Cirzen/bf3a16cf1b8c7130377a to your computer and use it in GitHub Desktop.
My attempt at the July 2015 Verified Effective practice question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .Synopsis | |
| Get simple Bios and OS info | |
| .DESCRIPTION | |
| Queries Win32_BIOS and Win32_Operating system over WsMan (default) or DCom protols to obtain Bios Serial, Service Pack Version and OSVersion info | |
| .EXAMPLE | |
| PS> Get-CorpSysInfo -ComputerName win81 -Protocol dcom | |
| BIOSSerial ComputerName SPVersion OSVersion | |
| ---------- ------------ --------- --------- | |
| VMware-56 4d 09 95 89 20 e... win81 0 6.3.9600 | |
| .EXAMPLE | |
| PS> Get-CorpSysInfo -ComputerName win81 -Verbose | |
| VERBOSE: Attempting connection to win81 over Wsman | |
| VERBOSE: Operation '' complete. | |
| VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, | |
| ''namespaceName' = root\cimv2,'className' = Win32_OperatingSystem'. | |
| VERBOSE: Operation 'Enumerate CimInstances' complete. | |
| VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, | |
| ''namespaceName' = root\cimv2,'className' = Win32_BIOS'. | |
| VERBOSE: Operation 'Enumerate CimInstances' complete. | |
| BIOSSerial ComputerName SPVersion OSVersion | |
| ---------- ------------ --------- --------- | |
| VMware-56 4d 09 95 89 20 e... win81 0 6.3.9600 | |
| #> | |
| #Requires -Version 3 | |
| function Get-CorpSysInfo | |
| { | |
| [CmdletBinding()] | |
| Param | |
| ( | |
| # ComputerName to connect to. Can be supplied by the pipeline | |
| [Parameter(Mandatory=$true, | |
| ValueFromPipeline=$true, | |
| Position=0)] | |
| [string[]] | |
| $ComputerName, | |
| # Protocol with which to establish Cim Session. Valid options are "WSMAN" (default) or "DCom" | |
| [Parameter(Mandatory=$false, | |
| Position=1)] | |
| [ValidateSet('Dcom','Wsman')] | |
| [string] | |
| $Protocol = 'WSMan' | |
| ) | |
| Begin | |
| { | |
| } | |
| Process | |
| { | |
| Write-Verbose "Process block started" | |
| ForEach ($Computer in $ComputerName) | |
| { | |
| Try | |
| { | |
| #Write-Verbose "Try block started" | |
| $Operation = $Null | |
| Write-Verbose "Attempting to connect to $Computer over $Protocol" | |
| $UseProtocol = New-CimSessionOption -Protocol $Protocol | |
| $Session = New-CimSession -ComputerName $Computer -SessionOption $UseProtocol -ErrorAction Stop | |
| #Write-Verbose "Operation '$Operation' Complete" | |
| $Operation = 'Enumerate CimInstances' | |
| $Namespace = 'root\cimv2' | |
| $ClassName = 'Win32_OperatingSystem' | |
| #Write-Verbose "Perform operation '$Operation' with following parameters, ''namespaceName' = $NameSpace,'className' = $ClassName'" | |
| $OS = Get-CimInstance -CimSession $Session -ClassName $ClassName -Namespace $Namespace | |
| #Write-Verbose "Operation '$Operation' Complete" | |
| $ClassName = 'Win32_BIOS' | |
| #Write-Verbose "Perform operation '$Operation' with following parameters, ''namespaceName' = $NameSpace,'className' = $ClassName'" | |
| $BIOS = Get-CimInstance -CimSession $Session -ClassName $ClassName -Namespace $Namespace | |
| #Write-Verbose "Operation '$Operation' Complete" | |
| New-Object PSCustomObject -Property @{ | |
| 'BIOSSerial'=$BIOS.SerialNumber | |
| 'ComputerName'=$Computer | |
| 'SPVersion'=$OS.ServicePackMajorVersion | |
| 'OSVersion'=$OS.Version}|Write-Output | |
| } | |
| Catch #Generic Catchall | |
| { | |
| Write-Error $_ | |
| Write-Warning "Failed establishing connection to $Computer" | |
| } | |
| }#End ForEach | |
| } #End Process | |
| End | |
| { | |
| } #End End | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment