Loose properties on my object

hello:
i do not understand why my last $obj do not has all properties like osversion, spversion as defined in the scriptt,

function Get-DetailedSystemInfo3 { 
    [CmdletBinding()] 
    param( 
        [Parameter(Mandatory=$True)][string[]]$computerName 
    ) 
    PROCESS { 
        foreach ($computer in $computerName) { 
            $params = @{computerName=$computer;            
                        class='Win32_OperatingSystem'}     
            $os = Get-WmiObject @params

            $params = @{computerName=$computer;            
                        class='Win32_LogicalDisk';         
                        filter='drivetype=3'}              
            $disks = Get-WmiObject @params
       
                    foreach ($disk in $disks) {  
                        $diskobjs  = [pscustomobject]@{
                                       Drive=$disk.DeviceID;   #$diskobjs instead of $diskprops      
                                       Size=$disk.size;          
                                       Free=$disk.freespace
                                       }     
      
                      $diskobjs                      
                    } # foreach disks
 
                
            $obj = [Pscustomobject][ordered]@{
                           ComputerName=$computer;         
                           Disks=$diskobjs; 
                           OSVersion=$os.version; 
                           SPVersion=$os.servicepackmajorversion
                           } 
  
           Write-Output $obj
        } # foreach comp
         
    } # process
} #function

i have understood , i need to comment the line $diskobjs
thank you

hey bin,

Also move $diskobjs to go outside of the foreach loop to get multiple disks.

as for the code, search the forum and you’ll find some good examples to use for reference. for example below covers what you’re trying to do

1 Like

yes, thank you very very much

You may also want to migrate to Get-CimInstance as Get-WmiObject has been deprecated.

Starting in PowerShell 3.0, this cmdlet has been superseded by Get-CimInstance.