Get-OS.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.Synopsis
   Get-OS does a WMI call to get basic operating system information.
.DESCRIPTION
   Get-OS does a WMI call to get basic operating system information.
.NOTES
   Created by: Jason Wasser @wasserja
   Modified: 5/15/2017 04:48:10 PM
.EXAMPLE
Get-OS
 
ComputerName : COMPUTER01
OS Name : Microsoft Windows 10 Enterprise
ServicePack : 0
Architecture : 64-bit
Version : 10.0.14393
OperatingSystemSKU : 4
InstallDate : 8/3/2016 2:10:49 PM
 
Gets the operating system information for the local system.
 
.EXAMPLE
Get-OS -ComputerName SERVER1
 
ComputerName : SERVER1
OS Name : Microsoft Windows Web Server 2008 R2
ServicePack : 1
Architecture : 64-bit
Version : 6.1.7601
OperatingSystemSKU : 17
InstallDate : 3/11/2011 2:24:33 AM
 
Get the operating system from SERVER1
.LINK
https://gallery.technet.microsoft.com/Get-OS-Get-Windows-7a140942
#>

function Get-OS {
    [CmdletBinding()]
    [Alias()]
    Param
    (
        [Parameter(Mandatory=$false,
                    ValueFromPipelineByPropertyName=$true,
                    ValuefromPipeline=$true,
                    Position=0)]
        [string[]]$ComputerName=$env:COMPUTERNAME
    )

    Begin
    {
    }
    Process
    {
        
        foreach ($Computer in $ComputerName) {
            $OSInfo = Get-WmiObject win32_OperatingSystem -ComputerName $Computer
            $OSInfo | Select-Object -Property @{Name="ComputerName";expression={$_.__SERVER}},@{Name="OS Name";expression={$_.Caption}},@{Name="ServicePack";expression={$_.ServicePackMajorVersion}},@{Name="Architecture";expression={$_.OSArchitecture}},Version,OperatingSystemSKU,@{Name='InstallDate';expression={$_.ConvertToDateTime($_.InstallDate)}}
            }
    }
    End
    {
    }
    }