I'm trying to determine how to properly call a variable for Get-WmiObject using a list of computers.
No matter what I do I cannot get this code to work.
I have spent a few hours reviewing code to compile the code I have and feel like I'm 90% there but can't get past this last little thing. I'm also new to Powershell but am trying my butt off
$comp = Import-CSV .\testlist.csv
foreach $comp{
$cs = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $comp
$bios = Get-CimInstance -ClassName Win32_BIOS -ComputerName $comp
$tpm = Get-WmiObject -Namespace root\cimv2\security\microsofttpm -Class Win32_Tpm -computername $comp -Authentication PacketPrivacy
$cos = Get-CimInstance -ClassName Win32_OperatingSystem -computername $comp | select-object Caption, BuildNumber, OSArchitecture
$properties = [ordered]@{
'ComputerName' = $comp;
'Model' = $cs.Model;
'Operating System' = $cos.Caption
'OS build' = $cos.BuildNumber
'OS Type' = $cos.OSArchitecture
'BIOSVersion' = $bios.SMBIOSBIOSVersion
'TPM ManufacturerId' = $tpm.ManufacturerId
'TPM Firmware version' = $tpm.ManufacturerVersion
'TPM SpecVersion' = $tpm.SpecVersion
)
}| Export-Csv -Path .\Result.csv -NoTypeInformation
Error Message:
New Text Document.ps1:4 char:8 + foreach $comp{ + ~ Missing opening '(' after keyword 'foreach'.
New Text Document.ps1:4 char:14 + foreach $comp{ + ~ Unexpected token '{' in expression or statement.
New Text Document.ps1:22 char:39 + 'TPM SpecVersion' = $tpm.SpecVersion + ~ The hash literal was incomplete.
New Text Document.ps1:4 char:14 + foreach $comp{ + ~ Missing closing '}' in statement block or type definition.
New Text Document.ps1:23 char:3 + ) + ~ Unexpected token ')' in expression or statement.
New Text Document.ps1:26 char:1 + }| Export-Csv -Path .\Result.csv -NoTypeInformation + ~ Unexpected token '}' in expression or statement.
New Text Document.ps1:26 char:2 + }| Export-Csv -Path .\Result.csv -NoTypeInformation + ~
An empty pipe element is not allowed. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword