首页 > 解决方案 > 如何检索在站点中进行最后修改的用户

问题描述

我必须使用 Power Shell 脚本检索在给定 Web 中进行最后修改的用户的名称。

我知道检索最后一个项目的修改日期很简单,但是如何检索进行此类修改的用户呢?

检索网络中最后修改的项目也可以,因为我会选择“修改者”字段的值。

标签: sharepoint

解决方案


所以......只是为了确认......您想检查某些网络中所有列表和库中的所有项目,并从每个列表中获取最后修改的项目并获取修改它的用户,对吗?:)

如果是这种情况,这种 PS 脚本应该可以解决问题



    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }

    try
    {
        $siteUrl="[URL]";
        $web = Get-SPWeb $siteUrl;

        $spQuery = New-Object Microsoft.SharePoint.SPQuery;
        $spQuery.ViewAttributes = "Scope='Recursive'";
        $spQuery.Query = ""
        $spQuery.RowLimit = 1;

        $lastDate = $null;
        $lastUser = $null;

        foreach($list in $web.Lists)
        {
            Write-Host 'checking list -' $list.Title;
            $items = $list.GetItems($spQuery);
            if($items.Count -gt 0)
            {
               if($lastDate -eq $null)
               {
                    $lastDate = $items[0]['Modified'];
                    $lastUser = $items[0]['Editor'];
               }
               else
               {
                    if((get-date $items[0]['Modified']) -gt (get-date $lastDate))
                    {
                        $lastDate = $items[0]['Modified'];
                        $lastUser = $items[0]['Editor'];
                    }
               }
            }
        }

        Write-Host 'last user that modfied some item in this web was - '$lastUser ' - ' $lastDate;
    }
    catch
    {
        Write-Host $_.Exception.Message; 
    }

我希望它有帮助:)。


推荐阅读