0
$computers = Import-Csv “C:\Temp\computers.csv” | ForEach { 
    $computerSystem = Get-WmiObject Win32_ComputerSystem -Name $_.Name
    $computerOS = Get-WmiObject Win32_OperatingSystem -Name $_.Name
    $computerCPU = Get-WmiObject Win32_Processor -Name $_.Name
    $computerSN = Get-WmiObject Win32_bios -Name $_.Name | Select-Object SerialNumber

    [PSCustomObject]@{    
        'PCName' = $computerSystem.Name    
        'Model'  = $computerSystem.Model   
        'RAM'    = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory / 1GB)    
        'CPU'    = $computerCPU.Name    
        'OS'     = $computerOS.caption
        'SN'     = $computerSN.SerialNumber
        'User'   = $computerSystem.UserName
    }
} | Export-Csv 'C:\Temp\system-info.csv' -NoTypeInformation

I used this as my powershell code, (copied bits from others - my csv file has 267 PC names in it - running as admin have admin rights (Also ran on a DC) ) but i am only getting 267 lines of my pn name and all the information i need - have a missed something or done something wrong here. any help greatly appreicetated

(New to powershell so still learning)

I expected to have 267 PC names seriel numbers, RAM, last loged in user. instead i am getting 267 rows of the same information from my pc

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • 1
    Replace `-Name` with `-ComputerName` when calling `Get-WmiObject` – Mathias R. Jessen May 04 '23 at 11:25
  • 1
    If you copy scripts from somewhere else (via Microsoft apps as Outlook), you should be careful with [smart quotes](https://stackoverflow.com/q/6968270/1701026) especially with *Windows* PowerShell (which you are apparently using, as you're using the old-fasion [`Get-WmiObject`](https://github.com/PowerShell/PowerShell/issues/15565) command) – iRon May 04 '23 at 11:32
  • As an aside: The CIM cmdlets (e.g., `Get-CimInstance`) superseded the WMI cmdlets (e.g., `Get-WmiObject`) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v6+, where all future effort will go, doesn't even _have_ them anymore. Note that WMI still _underlies_ the CIM cmdlets, however. For more information, see [this answer](https://stackoverflow.com/a/54508009/45375). – mklement0 May 04 '23 at 11:57
  • DCOM or WSMan would have to be enabled on the remote computers. – js2010 May 04 '23 at 14:11
  • thanks everyone - the get wmi object was literally the only one i could find to pull the seriel number - we have some n intune but im not convinced its a full and accurate list – Katrina May 05 '23 at 10:13

0 Answers0