简体   繁体   English

使用Powershell从sccm获取用户的上次登录

[英]Get user's last logon from sccm with powershell

I'm trying to create wmi query to sccm to get PC, where was user's last logon. 我正在尝试创建wmi查询到sccm以获取PC,这是用户的最后登录位置。 Something like: 就像是:

Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select lastlogon, PCname from sms_? where LastLogonUserName='$SamAccountName'" | select lastlogon, PCname.

I can see this information in sccm report, but I don't know what class I have to use for a query. 我可以在sccm报告中看到此信息,但是我不知道查询必须使用什么类。 I'm using sms_r_system for getting IP and computer name. 我正在使用sms_r_system获取IP和计算机名称。

Is anyone knew sccm class with this information or sql queries will be better for me? 有谁知道sccm类具有此信息或sql查询对我会更好?

Which report are you viewing the data with? 您正在使用哪个报告查看数据? You might want to open up the report's SQL code, figure out which ConfigMgr SQL views it's referencing, and then translate that to the SCCM WMI class names. 您可能要打开报告的SQL代码,找出它所引用的ConfigMgr SQL视图,然后将其转换为SCCM WMI类名称。 The WMI class names closely correlate to the SQL view names. WMI类名称与SQL视图名称紧密相关。

Use a WMI browser like SAPIEN's free WMI Explorer GUI tool to help explore the root\\sms\\site_xyz WMI namespace and discover which class you are looking for. 使用像SAPIEN的免费WMI Explorer GUI工具这样的WMI浏览器来帮助探索root \\ sms \\ site_xyz WMI名称空间并发现您要寻找的类。 You can also use Windows PowerShell to help discover which class contains this property: 您还可以使用Windows PowerShell帮助发现哪个类包含此属性:

gwmi -name root\cimv2 -list | ? { ($_.Properties.Name -join ',') -match 'lastlogon' }

Note : Make sure you're using PowerShell version 3.0 Release Preview for the above command, otherwise it won't work right. 注意 :请确保您使用的是上述命令的PowerShell版本3.0 Release Preview,否则它将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM