[英]Get primary user of device through SCCM query in PowerShell
We're scanning the active directory to find all computer objects.我们正在扫描活动目录以查找所有计算机对象。 Then for each machine we're trying to find the user that used that machine the most, ie the primary user.然后对于每台机器,我们试图找到使用该机器最多的用户,即主要用户。
To find this data we found 2 working queries towards SCCM:为了找到这些数据,我们发现了 2 个针对 SCCM 的工作查询:
$Query = "
SELECT
SMS_R_User.FullUserName, SMS_R_User.UniqueUserName, SMS_R_System.Name
FROM
SMS_R_System
INNER JOIN
SMS_G_System_SYSTEM_CONSOLE_USAGE
ON
SMS_G_System_SYSTEM_CONSOLE_USAGE.ResourceId = SMS_R_System.ResourceId
INNER JOIN
SMS_R_User
ON
SMS_G_System_SYSTEM_CONSOLE_USAGE.TopConsoleUser = SMS_R_User.UniqueUserName
"
$Query = "
SELECT
SMS_R_System.name, SMS_R_User.UniqueUserName
FROM
SMS_R_System
INNER JOIN
SMS_UserMachineRelationship
ON
SMS_UserMachineRelationship.ResourceId = SMS_R_System.ResourceId
JOIN
SMS_R_User
ON
SMS_UserMachineRelationship.UniqueUserName = SMS_R_User.UniqueUserName
WHERE
SMS_UserMachineRelationship.Types = 1
"
We execute these with:我们执行这些:
$WmiParams = @{
Namespace = "root\SMS\site_EU1"
ComputerName = $SCCMServer
Query = $Query
}
$Result = Get-WmiObject @WmiParams
We're not much of SCCM experts but both queries give different results and duplicate computer objects $Result.SMS_R_System.Name | Group-Object | where Count -ge 2
我们不是很多 SCCM 专家,但两个查询都给出了不同的结果和重复的计算机对象$Result.SMS_R_System.Name | Group-Object | where Count -ge 2
$Result.SMS_R_System.Name | Group-Object | where Count -ge 2
$Result.SMS_R_System.Name | Group-Object | where Count -ge 2
. $Result.SMS_R_System.Name | Group-Object | where Count -ge 2
。
What is the correct query to have one machine name connected to one primary user with SamAccountName
and FullUserName
?将一台机器名称连接到一个具有SamAccountName
和FullUserName
主要用户的正确查询是什么?
Thank you for your help.感谢您的帮助。
SMS_UserMachineRelationship
should contain Primary device for users. SMS_UserMachineRelationship
应包含用户的主要设备。 It's possible that 1 device can be Primary device of many users, and also 1 user can have more than 1 Primary device. 1 台设备可能是多个用户的主设备,也可能 1 个用户拥有 1 个以上的主设备。 It depends on the criteria configured in Client Settings
to identify Primary device.这取决于Client Settings
配置的标准来识别主设备。 By default if some users logs into a device for 48 hours
in a month then it's considered as Primary device of that user.默认情况下,如果某些用户在一个月48 hours
登录设备48 hours
,则将其视为该用户的主要设备。 This criteria can be changed.这个标准是可以改变的。 You may read more about User Device Affinity
at https://docs.microsoft.com/en-us/sccm/apps/deploy-use/link-users-and-devices-with-user-device-affinity您可以在https://docs.microsoft.com/en-us/sccm/apps/deploy-use/link-users-and-devices-with-user-device-affinity阅读有关User Device Affinity
更多信息
另一种选择是使用 PowerShell 模块“dbatools”...
Invoke-DbaQuery -SqlInstance "myserver.contoso.local" -Database "CM_P01" -Query "select UniqueUserName,MachineResource Name from v_UserMachineRelationship"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.