cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
re_my
Engaged Sweeper

Hello,

I'd like to make a report of all my Windows PCs and I'd like to have information on the disk containing my c:\ system partition.
I've managed to retrieve the information I need, but for the moment I have duplicates for PCs with several disks.

Here's my SQL:

 

 

 

Select Distinct Top (1000000) tblAssets.AssetID,
  tblAssets.AssetName,
  tblAssets.Domain,
  tblState.Statename,
  tblAssets.Username,
  tsysIPLocations.IPLocation,
  Case
    When t4.Win32_Batteryid Is Null Then 'Fixe'
    Else 'Portable'
  End As Type,
  tblAssetCustom.Manufacturer,
  tblAssetCustom.Model,
  tblAssetCustom.Serialnumber,
  Cast(tblAssetCustom.PurchaseDate As date) As Achat,
  Cast(tblAssetCustom.Warrantydate As date) As Garantie,
  Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon,
  tsysOS.OSname As OS,
  tblAssets.Version As [OS Version],
  tblProcessor.NumberOfCores As '# Cores',
  tblAssets.Processor,
  Cast(Cast(Round(tblAssets.Memory / 1024, 0, 0) As DECIMAL(20,0)) As varchar) +
  ' GB' As 'Memoire',
  Cast(Cast(Round(tblFloppy.Size / 1024 / 1024 / 1024, -1, 0) As DECIMAL(20,0))
  As varchar) + ' GB' As 'Disque',
  SubQuery1.DriveType As 'Disk Type',
  Case
    When (tblFloppy.InterfaceType = 'SCSI') Then 'PCIe'
    When (tblFloppy.InterfaceType = 'IDE') Then 'SATA'
    Else tblFloppy.InterfaceType
  End As [Disk Interface],
  tblFloppy.Model As 'Disk Model',
  Stuff((Select ', ' + Cast(t5.Caption As varchar(30))
    From tblVideoController t5
    Where t6.AssetID = t5.AssetID For Xml Path('')), 1, 2,
  '') [Carte graphique],
  Case
    When countMonitor.numberMonitors > 0 Then countMonitor.numberMonitors
    Else 0
  End As [# Ecrans],
  Stuff((Select ', ' + Cast(Case
        When t2.MonitorManufacturer = 'ACR' Then 'Acer'
        When t2.MonitorManufacturer = 'ACI' Then 'Asus'
        When t2.MonitorManufacturer = 'BNQ' Then 'BenQ'
        When t2.MonitorManufacturer = 'HWP' Then 'HP'
        When t2.MonitorManufacturer = 'HPN' Then 'HP'
        When t2.MonitorManufacturer = 'LEN' Then 'Lenovo'
        When t2.MonitorManufacturer = 'LGD' Then 'LG'
        When t2.MonitorManufacturer = 'LPL' Then 'LG'
        When t2.MonitorManufacturer = 'GSM' Then 'LG'
        When t2.MonitorManufacturer = 'PHL' Then 'Philips'
        When t2.MonitorManufacturer = 'SEC' Then 'Samsung'
        When t2.MonitorManufacturer = 'IVM' Then 'Iiyama'
        When t2.MonitorManufacturer = 'MAX' Then 'Maxdata'
        When t2.MonitorManufacturer = 'SNY' Then 'Sony'
        When t2.MonitorManufacturer = 'SYN' Then 'Samsung'
        When t2.MonitorManufacturer = 'ENC' Then 'EIZO'
        When t2.MonitorManufacturer = 'HSD' Then 'Hanns.G'
        When t2.MonitorManufacturer = 'VSC' Then 'ViewSonic'
        When t2.MonitorManufacturer = 'NEC' Then 'NEC Technologies'
        When t2.MonitorManufacturer = 'FUS' Then 'Fujitsu Siemens'
        When t2.MonitorManufacturer = 'BOE' Then 'BOE Technology'
        When t2.MonitorManufacturer = 'CMN' Then 'Chi Mei Innolux'
        When t2.MonitorManufacturer = 'AIC' Then 'Neovo'
        When t2.MonitorManufacturer = 'ZDH' Then 'Dahua'
        When t2.MonitorManufacturer Like '%FUJ%' Then 'Fujitsu Siemens'
        When t2.MonitorManufacturer Like '%AOC%' Then 'AOC'
        When t2.MonitorManufacturer Like '%DEL%' Then 'Dell'
        When t2.MonitorManufacturer Like '%SAM%' Then 'Samsung'
        When t2.MonitorManufacturer Like '%Lenovo%' Then 'Lenovo'
        When t2.MonitorManufacturer Like 'AUO' Then 'AU Optronics'
        When t2.MonitorManufacturer Like 'BenQ' Then 'BenQ'
        Else t2.MonitorManufacturer
      End As varchar(15)) From tblMonitor t2
    Where t1.AssetID = t2.AssetID And t2.MonitorModel Not Like '%?%' And
      t2.MonitorModel Not Like '%.%' For Xml Path('')), 1, 2,
  '') [Ecran Marque],
  Stuff((Select ', ' + Cast(t2.MonitorModel As varchar(30)) From tblMonitor t2
    Where t1.AssetID = t2.AssetID And t2.MonitorModel Not Like '%?%' And
      t2.MonitorModel Not Like '%.%' For Xml Path('')), 1, 2,
  '') [Ecran Modele],
  Stuff((Select ', ' + Cast(t2.SerialNumber As varchar(30)) From tblMonitor t2
    Where t1.AssetID = t2.AssetID And t2.MonitorModel Not Like '%?%' And
      t2.MonitorModel Not Like '%.%' For Xml Path('')), 1, 2,
  '') [Ecran N° Serie],
  Stuff((Select ', ' + Cast(t3.Name As varchar(30)) From tblBattery t3
    Where t4.AssetID = t3.AssetID For Xml Path('')), 1, 2, '') Batteries,
  tblAssets.Lastseen,
  tblAssets.Lasttried
From tblAssets
  Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
  Inner Join tblFloppy On tblAssets.AssetID = tblFloppy.AssetID
  Inner Join tblState On tblAssetCustom.State = tblState.State
  Left Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID
  Left Join tblMonitor t1 On tblAssets.AssetID = t1.AssetID
  Left Join (Select tblMonitor.AssetID,
      Count(tblMonitor.MonitorID) As numberMonitors
    From tblMonitor
    Where tblMonitor.MonitorModel Not Like '%?%' And
      tblMonitor.MonitorModel Not Like '%.%'
    Group By tblMonitor.AssetID) countMonitor On countMonitor.AssetID =
      tblAssets.AssetID
  Left Join tsysOS On tsysOS.OScode = tblAssets.OScode
  Left Join tblVideoController t6 On tblAssets.AssetID = t6.AssetID
  Left Join tblBattery t4 On tblAssets.AssetID = t4.AssetID
  Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
  Left Join tblProcessor On tblAssets.AssetID = tblProcessor.AssetID
  Left Join (Select Top 1000000 tblRegistry.AssetID,
      tblRegistry.Value,
      SubString(tblRegistry.Value, CharIndex('FriendlyName=', tblRegistry.Value)
      + Len('FriendlyName='), CharIndex(';', tblRegistry.Value) -
      CharIndex('FriendlyName=', tblRegistry.Value) - Len('FriendlyName=')) As
      DriveName,
      SubString(tblRegistry.Value, CharIndex('MediaType=', tblRegistry.Value) +
      Len('MediaType='), CharIndex('}', tblRegistry.Value) -
      CharIndex('MediaType=', tblRegistry.Value) - Len('MediaType=')) As
      DriveType
    From tblRegistry
    Where tblRegistry.Regkey Like '%System\HDD' And
      tblRegistry.Valuename In ('0', '1', '2', '3', '4', '5', '6', '7', '8',
      '9')) SubQuery1 On SubQuery1.DriveName = tblFloppy.Model
Where tblAssets.AssetName Not Like '%PDMTASK%' And
  tblAssetCustom.Manufacturer Not Like '%VMware%' And (tsysOS.OSname = 'Win 10'
    Or tsysOS.OSname = 'Win 11') And tblFloppy.Partitions > 1 And
  tblFloppy.InterfaceType <> 'USB'
Order By tblAssets.AssetName

 

 

 Thanks for your help

0 REPLIES 0