Advertisement
Guest User

Get-OSVersion

a guest
Oct 9th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-OSVersion {
  2.     <#
  3.     .SYNOPSIS
  4.     Версия текущей ОС
  5.     .DESCRIPTION
  6.     Функция для получения информации о версии текущей операционной системы
  7.     .OUTPUTS
  8.     [System.Management.Automation.PSCustomObject] объект с информацией об ОС
  9.     .NOTES
  10.     Автор:          iNNOKENTIY21
  11.     .EXAMPLE
  12.     Get-OSVersion
  13.     .EXAMPLE
  14.     Get-OSVersion | Format-Table
  15.     .EXAMPLE
  16.     (Get-OSVersion).ReleaseId
  17.     #>
  18.  
  19.     $signature = @'
  20. [DllImport("kernel32.dll")]
  21. public static extern uint GetVersion();
  22. '@
  23.  
  24.     Add-Type -MemberDefinition $signature -Name "OSVersion" -Namespace Win32API
  25.  
  26.     $OSVersion          = [Win32API.OSVersion]::GetVersion()
  27.     $os                 = [System.BitConverter]::GetBytes($OSVersion)
  28.     $build              = [byte]$os[2], [byte]$os[3]
  29.     $Path               = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
  30.     $ProductName        = Get-ItemProperty -Path $Path -Name ProductName
  31.     $EditionID          = Get-ItemProperty -Path $Path -Name EditionID
  32.     $ReleaseId          = Get-ItemProperty -Path $Path -Name ReleaseId
  33.     $CurrentVersion     = Get-ItemProperty -Path $Path -Name CurrentVersion
  34.     $InstallationType   = Get-ItemProperty -Path $Path -Name InstallationType
  35.     $CurrentBuild       = Get-ItemProperty -Path $Path -Name CurrentBuild
  36.     $CurrentBuildNumber = Get-ItemProperty -Path $Path -Name CurrentBuildNumber
  37.     $UBR                = Get-ItemProperty -Path $Path -Name UBR
  38.  
  39.     [PSCustomObject]@{
  40.         # Registry
  41.         ProductName          = ($ProductName).ProductName
  42.         EditionID            = ($EditionID).EditionID
  43.         ReleaseId            = [int]($ReleaseId).ReleaseId
  44.         CurrentVersion       = [double]($CurrentVersion).CurrentVersion
  45.         InstallationType     = ($InstallationType).InstallationType
  46.         CurrentBuild         = ($CurrentBuild).CurrentBuild
  47.         CurrentBuildNumber   = ($CurrentBuildNumber).CurrentBuildNumber
  48.         UBR                  = ($UBR).UBR
  49.  
  50.         # kernel32.dll GetVersion()
  51.         Major                = $os[0]
  52.         Minor                = $os[1]
  53.         Build                = [System.BitConverter]::ToInt16($build, 0)
  54.  
  55.         # System.Environment
  56.         EnvironmentOSVersion = [System.Environment]::OSVersion.Version
  57.  
  58.         # CimInstance
  59.         CimInstanceOSVersion = (Get-CimInstance Win32_OperatingSystem).version
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement