Last active
August 29, 2015 14:25
-
-
Save bgelens/dda61571caf95a0ffe26 to your computer and use it in GitHub Desktop.
This file contains 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
function Get-CorpSysInfo { | |
[cmdletbinding()] | |
param ( | |
[Parameter(ValueFromPipeline, | |
ValueFromPipelineByPropertyName)] | |
[ValidateNotNullOrEmpty()] | |
[String[]] $ComputerName = $env:COMPUTERNAME, | |
[ValidateSet('dcom','Wsman')] | |
[String] $Protocol = 'Wsman' | |
) | |
process { | |
foreach ($Computer in $ComputerName) { | |
try { | |
$Session = $null | |
Write-Verbose -Message "Attempting connection to $Computer over $Protocol" | |
$option = New-CimSessionOption -Protocol $Protocol | |
$Session = New-CimSession -ComputerName $Computer -SessionOption $option | |
if ($Session -eq $null) { | |
Write-Warning -Message "Failed establishing $Protocol session to $Computer" | |
continue | |
} | |
$OS = Get-CimInstance -CimSession $Session -ClassName Win32_OperatingSystem | |
$Bios = Get-CimInstance -CimSession $Session -ClassName win32_bios | |
$output = [ordered]@{ | |
BIOSSerial = $Bios.SerialNumber | |
ComputerName = $C | |
SPVersion = $os.ServicePackMajorVersion | |
OSVersion = $os.Version | |
} | |
$obj = New-Object -TypeName pscustomobject -Property $output | |
Write-Output -InputObject $obj | |
} | |
finally { | |
if ($Session) { | |
$Session | Remove-CimSession | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment