I'm a newcomer to Powershell, and I want to run everything in my Custom Object which $info for all of the computers in $computerName in order to get their information. In this code, I've named them A, B, C for general reference. I tried implementing a foreach loop to write-host of $info so that it would accomplish the task but it's not working. I also tried just just running $info.OSInfo for the CustomObjects, but nothing happens when I run the file in VS Code. Would appreciate your help.
Function Get-SystemInfo {
[CmdletBinding()]
param (
[Parameter()]
[string]
$computerName
)
$compSysProps = @{ Property = @('Name','Model','NumberOfProcessors','Manufacturer','Domain','NumberOfLogicalProcessors','TotalPhysicalMemory'); }
$OsInfoProps = @{ Property = @('Property', 'InstallDate', 'Caption', 'Version');}
$BiosProps = @{ Property = @('SerialNumber'); }
$ProcessorProps = @{ Property = @('Name', 'NumberofCores','NumberofLogicalProcessors', 'SocketDesignation');}
$DiskProps = @{ Property = @('Caption', 'Size', 'FreeSpace'); }
$computerName = @('A','B','C')
foreach ($computer in $computerName)
{
Write-Host $info
}
$info = [PSCustomObject]@{
OSInfo = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $computerName | Select-Object @OsInfoProps
BIOSInfo = Get-CimInstance -ClassName Win32_bios -ComputerName $computerName | Select-Object @BiosProps
ComputerSystemInfo = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $computerName | Select-Object @compSysProps
ProcessorInfo = Get-CimInstance -Class Win32_processor -ComputerName $computerName| Select-Object @ProcessorProps
DiskInfo = Get-CimInstance -Class Win32_LogicalDisk -ComputerName $computerName | Select-Object @DiskProps
}
}