-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path10_2.ps1
More file actions
29 lines (28 loc) · 957 Bytes
/
10_2.ps1
File metadata and controls
29 lines (28 loc) · 957 Bytes
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
function Get-MachineInfo {
Param(
[string[]]$ComputerName,
[string]$LogFailuresToPath,
[string]$Protocol = "Wsman",
[switch]$ProtocolFallback
)
foreach ($computer in $computername) {
# Establish session protocol
if ($protocol -eq 'Dcom') {
$option = New-CimSessionOption -Protocol Dcom
} else {
$option = New-CimSessionOption -Protocol Wsman
}
$session = New-CimSession -ComputerName $computer -SessionOption $option #A
# Query data
$os = Get-CimInstance -ClassName Win32_OperatingSystem -CimSession #B
➥ $session
# Close session
$session | Remove-CimSession
# Output data
$os | Select-Object -Prop @{n='ComputerName';e={$computer}},
Version,ServicePackMajorVersion #C
} #foreach
} #function
#A Connects the session
#B Queries for operating system data
#C Writes the output using Select-Object