Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement