gpt4 book ai didi

powershell - Sitecore Powershell : Find users last login?

转载 作者:行者123 更新时间:2023-12-03 11:17:46 25 4
gpt4 key购买 nike

我正在编写一个非常简单的 Sitecore PowerShell 脚本来报告我们系统中的所有用户。我们想知道每个用户的最后登录日期,但我没有运气。我可以访问 $_.Profile.LastActivityDate,但这无济于事,因为它似乎对所有用户来说都是相同的值。任何想法访问上次登录日期的表达式是什么,或者我如何找到它?谢谢。

Get-User -Filter * |

Show-ListView -Property @{Label="User"; Expression={ $_.Profile.UserName} },
@{Label="Full Name"; Expression={ $_.Profile.FullName} },
@{Label="Email"; Expression={ $_.Profile.Email} },
@{Label="Logged In"; Expression={ $_.Profile.LastActivityDate } }

Close-Window

最佳答案

Get-User 将输出一个或多个 Sitecore.Security.Accounts.User ,其 Profile属性是 Sitecore.Security.UserProfile继承自 System.Web.Profile.ProfileBase .所以,LastActivityDate属性应该与您通过访问 Sitecore 之外的配置文件获得的相同。

也就是说,仅访问配置文件数据就有可能更新上次事件日期。

The LastActivityDate for a user is updated by the classes in the System.Web.Profile and the System.Web.UI.WebControls.WebParts namespaces whenever user data is retrieved from or set at the data source. ...



因此,您可以避免访问配置文件,而是检索 MembershipUsers。 MembershipUser有一个名为 LastLoginDate 的属性我认为这就是你所追求的:
[System.Web.Security.Membership]::GetAllUsers() |

Show-ListView -Property @{Label="User"; Expression={ $_.UserName} },
@{Label="Is Online"; Expression={ $_.IsOnline} },
@{Label="Creation Date"; Expression={ $_.CreationDate} },
@{Label="Last Login Date"; Expression={ $_.LastLoginDate} },
@{Label="Last Activity Date"; Expression={ $_.LastActivityDate } }

如果您需要在不更新上次事件日期的情况下访问配置文件,您还可以尝试:
[System.Web.Security.Membership]::GetUser("sitecore\admin", $false)

关于powershell - Sitecore Powershell : Find users last login?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38340617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com