Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. function Get-CorpSysInfo {
  2. [cmdletbinding()]
  3. param (
  4. [Parameter(ValueFromPipeline,
  5. ValueFromPipelineByPropertyName)]
  6. [ValidateNotNullOrEmpty()]
  7. [String[]] $ComputerName = $env:COMPUTERNAME,
  8.  
  9. [ValidateSet('dcom','Wsman')]
  10. [String] $Protocol = 'Wsman'
  11. )
  12. process {
  13. foreach ($Computer in $ComputerName) {
  14. try {
  15. $Session = $null
  16. Write-Verbose -Message "Attempting connection to $Computer over $Protocol"
  17. $option = New-CimSessionOption -Protocol $Protocol
  18. $Session = New-CimSession -ComputerName $Computer -SessionOption $option
  19. if ($Session -eq $null) {
  20. Write-Warning -Message "Failed establishing $Protocol session to $Computer"
  21. continue
  22. }
  23. $OS = Get-CimInstance -CimSession $Session -ClassName Win32_OperatingSystem
  24. $Bios = Get-CimInstance -CimSession $Session -ClassName win32_bios
  25.  
  26. $output = [ordered]@{
  27. BIOSSerial = $Bios.SerialNumber
  28. ComputerName = $C
  29. SPVersion = $os.ServicePackMajorVersion
  30. OSVersion = $os.Version
  31. }
  32. $obj = New-Object -TypeName pscustomobject -Property $output
  33. Write-Output -InputObject $obj
  34. }
  35. finally {
  36. if ($Session) {
  37. $Session | Remove-CimSession
  38. }
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement