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);

        SPAuditEntryCollection auditCol = site.Audit.GetEntries(query);

        foreach (SPAuditEntry entry in auditCol)

1 Answer 1

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;       
    $spSite=Get-SPSite -Identity "http://sp/sites/dev" 
    $spAuditQuery=New-Object Microsoft.SharePoint.SPAuditQuery($spSite)
    $Today = [DateTime]::Today
    $DateLimit = $Today.AddDays(-7)
    foreach($spAuditEntry in $spAuditEntries){ 
        Write-Host $spAuditEntry.EventName

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, 2017 at 7:05
  • Changed code. This is working fine for me. I guess exact same code for your SOM code.
    – newbie
    Jul 4, 2017 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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