Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-OSVersion {
- <#
- .SYNOPSIS
- Версия текущей ОС
- .DESCRIPTION
- Функция для получения информации о версии текущей операционной системы
- .OUTPUTS
- [System.Management.Automation.PSCustomObject] объект с информацией об ОС
- .NOTES
- Автор: iNNOKENTIY21
- .EXAMPLE
- Get-OSVersion
- .EXAMPLE
- Get-OSVersion | Format-Table
- .EXAMPLE
- (Get-OSVersion).ReleaseId
- #>
- $signature = @'
- [DllImport("kernel32.dll")]
- public static extern uint GetVersion();
- '@
- Add-Type -MemberDefinition $signature -Name "OSVersion" -Namespace Win32API
- $OSVersion = [Win32API.OSVersion]::GetVersion()
- $os = [System.BitConverter]::GetBytes($OSVersion)
- $build = [byte]$os[2], [byte]$os[3]
- $Path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
- $ProductName = Get-ItemProperty -Path $Path -Name ProductName
- $EditionID = Get-ItemProperty -Path $Path -Name EditionID
- $ReleaseId = Get-ItemProperty -Path $Path -Name ReleaseId
- $CurrentVersion = Get-ItemProperty -Path $Path -Name CurrentVersion
- $InstallationType = Get-ItemProperty -Path $Path -Name InstallationType
- $CurrentBuild = Get-ItemProperty -Path $Path -Name CurrentBuild
- $CurrentBuildNumber = Get-ItemProperty -Path $Path -Name CurrentBuildNumber
- $UBR = Get-ItemProperty -Path $Path -Name UBR
- [PSCustomObject]@{
- # Registry
- ProductName = ($ProductName).ProductName
- EditionID = ($EditionID).EditionID
- ReleaseId = [int]($ReleaseId).ReleaseId
- CurrentVersion = [double]($CurrentVersion).CurrentVersion
- InstallationType = ($InstallationType).InstallationType
- CurrentBuild = ($CurrentBuild).CurrentBuild
- CurrentBuildNumber = ($CurrentBuildNumber).CurrentBuildNumber
- UBR = ($UBR).UBR
- # kernel32.dll GetVersion()
- Major = $os[0]
- Minor = $os[1]
- Build = [System.BitConverter]::ToInt16($build, 0)
- # System.Environment
- EnvironmentOSVersion = [System.Environment]::OSVersion.Version
- # CimInstance
- CimInstanceOSVersion = (Get-CimInstance Win32_OperatingSystem).version
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement