-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path13_1.ps1
More file actions
61 lines (61 loc) · 2.41 KB
/
13_1.ps1
File metadata and controls
61 lines (61 loc) · 2.41 KB
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
function Get-MachineInfo {
[CmdletBinding()] #A
Param(
[Parameter(ValueFromPipeline=$True,
Mandatory=$True)]
[Alias('CN','MachineName','Name')]
[string[]]$ComputerName,
[string]$LogFailuresToPath,
[ValidateSet('Wsman','Dcom')]
[string]$Protocol = "Wsman",
[switch]$ProtocolFallback
)
BEGIN {}
PROCESS {
foreach ($computer in $computername) {
if ($protocol -eq 'Dcom') {
$option = New-CimSessionOption -Protocol Dcom
} else {
$option = New-CimSessionOption -Protocol Wsman
}
Write-Verbose "Connecting to $computer over $protocol" #B
$session = New-CimSession -ComputerName $computer `
-SessionOption $option
Write-Verbose "Querying from $computer"
$os_params = @{'ClassName'='Win32_OperatingSystem'
'CimSession'=$session}
$os = Get-CimInstance @os_params
$cs_params = @{'ClassName'='Win32_ComputerSystem'
'CimSession'=$session}
$cs = Get-CimInstance @cs_params
$sysdrive = $os.SystemDrive
$drive_params = @{'ClassName'='Win32_LogicalDisk'
'Filter'="DeviceId='$sysdrive'"
'CimSession'=$session}
$drive = Get-CimInstance @drive_params
$proc_params = @{'ClassName'='Win32_Processor'
'CimSession'=$session}
$proc = Get-CimInstance @proc_params |
Select-Object -first 1
Write-Verbose "Closing session to $computer"
$session | Remove-CimSession
Write-Verbose "Outputting for $computer"
$obj = [pscustomobject]@{'ComputerName'=$computer #C
'OSVersion'=$os.version
'SPVersion'=$os.servicepackmajorversion
'OSBuild'=$os.buildnumber
'Manufacturer'=$cs.manufacturer
'Model'=$cs.model
'Procs'=$cs.numberofprocessors
'Cores'=$cs.numberoflogicalprocessors
'RAM'=($cs.totalphysicalmemory / 1GB)
'Arch'=$proc.addresswidth
'SysDriveFreeSpace'=$drive.freespace}
Write-Output $obj
} #foreach
} #PROCESS
END {}
} #function
#A [CmdletBinding()] is added just prior to the param block
#B Uses verbose messages
#C Uses [pscustomobject]