我们正在尝试检索来自SCCM内多个表的数据。目前,我们使用PowerShell使用所需的数据来格式化对象。
如果我们可以更改SELECT
语句以包含多个表(如SELECT SMS_G_System_COMPUTER_SYSTEM.Model, SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes FROM ...
)中的字段,那就太好了。但这似乎是不可能的。即使使用别名AS
也没有。
是否有比我们下面发现的解决方法更好或更简单的方法?
$Query = "
SELECT *
FROM
SMS_R_System
INNER JOIN
SMS_G_System_COMPUTER_SYSTEM
ON
SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId
INNER JOIN
SMS_G_System_SYSTEM_ENCLOSURE
ON
SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId
"
$WMIQueryParams = @{
NameSpace = $NameSpace
ComputerName = $SCCMServer
Query = $Query
}
$Result = Get-WmiObject @WMIQueryParams | select -First 1
$Result |
Select-Object @{N = 'Name'; E = { $_.SMS_G_System_COMPUTER_SYSTEM.Name}},
@{N = 'Manufacturer'; E = { $_.SMS_G_System_COMPUTER_SYSTEM.Manufacturer}},
@{N = 'Model'; E = { $_.SMS_G_System_COMPUTER_SYSTEM.Model}},
@{N = 'ChassisTypes'; E = { $_.SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes}},
@{N = 'DeviceType'; E = {
switch -Regex ($_.SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes) {
'8|9|10|11|12|14|18|21' { 'Laptop' }
'3|4|5|6|7|15|16' { 'Desktop' }
'23' { 'Server' }
Default {'Unknown'}
}
}},
@{N = 'OS'; E = { $_.SMS_R_System.operatingSystem}},
@{N = 'OSversion'; E = { $_.SMS_R_System.operatingSystemVersion}}