Public/Query-ComputerInfo.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
function Query-ComputerInfo {

    <#
    .SYNOPSIS
        Query basic system information.
 
    .DESCRIPTION
        Query basic system information about the target computer.
 
    .NOTES
        Author: Greg Powers
    #>


    [CmdletBinding()]
    param (
        # ComputerName --
        [Parameter(
            Position=0,
            Mandatory=$true,
            ValueFromPipeline=$true
        )]
        [System.Object]
        $ComputerName
    )
    
    begin {
    }
    
    process {
        foreach ($Computer in $ComputerName) {
            $CIMSession = New-CimSession -ComputerName $Computer
            $ComputerInfo = Get-CimInstance -CimSession $CIMSession -ClassName Win32_OperatingSystem
            Remove-CimSession -CimSession $CIMSession
            [PSCustomObject]@{
                Computer = $ComputerInfo.CSName
                OperatingSystem = $ComputerInfo.Caption
                OSVer = $ComputerInfo.Version
                WinDir = $ComputerInfo.WindowsDirectory
            }
        }
    }
    
    end {
    }
}