Create a gist now

Instantly share code, notes, and snippets.

@dlwyatt /Attempt1.ps1 Secret
Last active Aug 29, 2015

What would you like to do?
Verified Effective Samples
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 }
}
}
}
}
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