ps-gethits

Title: Get the hits from IIS logs who accessed the Myname.aspx page

Description: Get all usernames who accesses the selected page. find based on keyword.

  1.   
  2.  ##################################################################################  
  3. # Written by : Bramhendra Lakku  
  4. # Approved by:  
  5. #  Script name: hits.ps1  
  6. #  Purpose: Get the  search key words#   
  7. #  Company:       
  8. # Input Parameters Format for report :N/A  
  9.  
  10. # Out Put: Output file will generated in this Folder  
  11. ##################################################################################  
  12.  
  13. # run with Farm admin account or provide the permissions to your account Go to Central Administration => Application Management => Manage Service Applications => User Profile Service Application.Click on Administrators => Add the user and give Full Control.  
  14.  
  15. #Click on Permissions => Add the user and give Full Control.  
  16. $date = Get-date -format "MMddyyy-hhmmss"  
  17. $OutPutFilename="Links-19-edit-$date.csv";  
  18. "Login ID" + "," +"Date(YYYY-MM-DD)"  | Out-File -Encoding Default -FilePath $OutPutFilename;  
  19.   
  20.    
  21.  function Get-DataByInput ($path, $id1, $id2)  
  22.      {  
  23.           $dataRegex = "$id1"  
  24.           $dataRegex1 = "$id2(.+)$"         
  25.             
  26.           Get-Content $path  | % {   
  27.             if ($_ -match $dataRegex )   
  28.                 {   
  29.                      
  30.                       
  31.                       
  32.                     if ($_ -match $dataRegex1 )   
  33.                         {  
  34.                          $Did=$matches[1];  
  35.                           
  36.                         $dateprint = $_.Substring(0,10) #adjest number  
  37.                         #write-host $dateprint  
  38.                         $Didname=$Did.Split(' ')[0].Replace("\","")  
  39.                     
  40.                      #write-host   $Did.Split(' ')[0] "#########" $SearchKeyWord.Split(' ')[0]   
  41.                      $Didname + ", " +$dateprint | Out-File -Encoding Default  -Append -FilePath $OutPutFilename;  
  42. }  
  43.                       
  44.                 }  
  45.           }  
  46.     }  
  47.   
  48. Get-ChildItem "E:\LogLocation" –Recurse -Filter *.log |   
  49. Foreach-Object {  
  50. # Make sure to include https and http requests  
  51. Get-DataByInput -path $_.FullName -id1 "Myname.aspx" -id2 "domainname"  
  52. #write-host $_.FullName  
  53.       
  54. }