0

Can any one help me the conversation of below code to Power-Shell

 SPSite site = new SPSite("http://sp/sites/dev");
        SPAuditQuery query = new SPAuditQuery(site);

        query.SetRangeStart(DateTime.Now.AddDays(-7));
        query.SetRangeEnd(DateTime.Now);
        SPAuditEntryCollection auditCol = site.Audit.GetEntries(query);

        foreach (SPAuditEntry entry in auditCol)
        {
            Console.WriteLine(entry.EventName);
        }
3
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;       
    $spSite=Get-SPSite -Identity "http://sp/sites/dev" 
    $spwWeb=$spSite.OpenWeb() 
    $spAuditQuery=New-Object Microsoft.SharePoint.SPAuditQuery($spSite)
    $Today = [DateTime]::Today
    $DateLimit = $Today.AddDays(-7)
    $spAuditQuery.SetRangeStart($DateLimit)
    $spAuditQuery.SetRangeEnd(($Today))
    $spAuditEntries=$spSite.Audit.GetEntries($spAuditQuery) 
    foreach($spAuditEntry in $spAuditEntries){ 
        Write-Host $spAuditEntry.EventName
    } 
    $spwWeb.Dispose()      
    $spSite.Dispose() 

I guess you are querying site audit logs. Maybe this link helps you.

  • Dear I am getting the Error as "GetSiteUserByID : The term 'GetSiteUserByID' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." – MSA Jul 4 '17 at 7:05
  • Changed code. This is working fine for me. I guess exact same code for your SOM code. – newbie Jul 4 '17 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.