我是 Powershell 的新手,我想为 $computerName 中的所有计算机运行我的自定义对象 $info 中的所有内容,以便获取它们的信息。在这段代码中,我将它们命名为 A、B、C 以供一般参考。我尝试实现一个 foreach 循环来写入 $info 的主机,以便它完成任务,但它不起作用。我也尝试只为 CustomObjects 运行 $info.OSInfo,但是当我在 VS Code 中运行文件时没有任何反应。感谢您的帮助。
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
}
}