Verified Effective Samples
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' | |
) | |
begin | |
{ | |
$option = New-CimSessionOption -Protocol $Protocol | |
} | |
process | |
{ | |
foreach ($computer in $ComputerName) | |
{ | |
$session = $null | |
try | |
{ | |
$session = New-CimSession -ComputerName $computer -SessionOption $option -ErrorAction Stop | |
$operatingSystem = Get-CimInstance -CimSession $session -ClassName Win32_OperatingSystem -ErrorAction Stop | |
$bios = Get-CimInstance -CimSession $session -ClassName Win32_BIOS -ErrorAction Stop | |
[pscustomobject] @{ | |
BIOSSerial = $bios.SerialNumber | |
ComputerName = $operatingSystem.CSName | |
SPVersion = $operatingSystem.ServicePackMajorVersion | |
OSVersion = $operatingSystem.Version | |
} | |
} | |
catch | |
{ | |
Write-Error -ErrorRecord $_ | |
continue | |
} | |
finally | |
{ | |
if ($session) { Remove-CimSession -CimSession $session } | |
} | |
} | |
} | |
} |
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' | |
) | |
begin | |
{ | |
$option = New-CimSessionOption -Protocol $Protocol | |
} | |
process | |
{ | |
foreach ($computer in $ComputerName) | |
{ | |
Write-Verbose "Attempting connection to $computer over $Protocol" | |
$session = $null | |
try | |
{ | |
$session = New-CimSession -ComputerName $computer -SessionOption $option | |
if ($null -eq $session) | |
{ | |
Write-Warning "Failed establishing $Protocol session to $computer" | |
continue | |
} | |
$operatingSystem = Get-CimInstance -CimSession $session -ClassName Win32_OperatingSystem | |
$bios = Get-CimInstance -CimSession $session -ClassName Win32_BIOS | |
[pscustomobject] @{ | |
BIOSSerial = $bios.SerialNumber | |
ComputerName = $operatingSystem.CSName | |
SPVersion = $operatingSystem.ServicePackMajorVersion | |
OSVersion = $operatingSystem.Version | |
} | |
} | |
finally | |
{ | |
if ($session) { Remove-CimSession -CimSession $session } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment