Chapters/using-verbose-warning-informational-output/Toolmaking-Prelim/Toolmaking-Prelim.psm1
function Get-MachineInfo { [CmdletBinding()] 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" $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 '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 |