简体   繁体   English

通过 PowerShell 中的 SCCM 查询获取设备的主要用户

[英]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 ?将一台机器名称连接到一个具有SamAccountNameFullUserName主要用户的正确查询是什么?

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.

相关问题 使用SCCM需要删除当前记录的用户配置文件下的文件夹,因此需要一个Powershell来查看“ C:\\ users”以获取用户并循环浏览它们 - Using SCCM need to remove a folder under current logged user profile, hence a powershell to look at “C:\users” to get users and cycle through them 使用Powershell从sccm获取用户的上次登录 - Get user's last logon from sccm with powershell Powershell / SCCM-通过Powershell(或其他)获取SCCM部署的“计划时间”? - Powershell/SCCM - Get an SCCM deployment “Scheduled time” via powershell (or other)? PowerShell:如何在SCCM 2012中创建设备? - PowerShell: How to create a device in SCCM 2012? 在Powershell中使用来自SCCM的WQL查询 - Using WQL query from SCCM in powershell 合并查询(WQL子选择查询-Powershell-SCCM) - Combine queries (WQL subselect query - Powershell - SCCM) SCCM PowerShell获取配置基准计算机 - SCCM PowerShell Get Configuration Baseline computers 通过SCCM安装时未显示Powershell弹出框 - Powershell Popup Box not showing when installing through SCCM 在 Azure AD 中,如何通过 PowerShell(例如 Set-AzureADUser 和 Get-AzureADUser)设置和读取用户的主要电子邮件? - In Azure AD, how to set and read a user's primary email through PowerShell (e.g. Set-AzureADUser and Get-AzureADUser)? 来自SCCM的本地用户的Powershell VSCode invoke-command - Powershell VSCode invoke-command from localhost different user for SCCM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM