SOLVED

Sharepoint shared excel file user active session?

Iron Contributor

Hi Community,

 

Is there a way to list all the user active session who opened the shared excel file in sharepoint?

Thanks.

3 Replies

@Alan2022 Do you want to check if user opened file for "viewing" or "editing"?

 

If you want to get the information related to who locked file for editing, you can use REST API endpoint like: 

 

_api/web/GetFileByServerRelativeUrl('URL')/lockedByUser

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

best response confirmed by Alan2022 (Iron Contributor)
Solution

Hi @ganeshsanap,

 

Thank you very much for the guide. With this PS script it can already view user who open the shared file in excel.

$UserName = ""
$Password = ""
$credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName,$Password

# Set Location of Sharepoint 
$url = "https://<name>.sharepoint.com/personal/<site>"

# Connect to Sharepoint
Connect-PnpOnline $url -Credential $credential

# Get Context
$clientContext = Get-PnPContext
 
# -Url: relative path of the file
# -AsListItem: Retrieves the file and returns it as a ListItem object
$ListItem = Get-PnPFile -Url "/Documents/<filename.xlsx>" -AsListItem

# Get the File object
$targetFile = $ListItem.File
 
$clientContext.Load($targetFile)
 
$clientContext.ExecuteQuery()

# Get user who locked out the file
$User = $targetFile.LockedByUser
 
$clientContext.Load($User)
 
$clientContext.ExecuteQuery()

if($User.Title){
    $User.Title
}
else{
    Write-Host "No User found!"
}
 
Disconnect-PnPOnline

 

Cheers :thumbs_up::thumbs_up::thumbs_up:.

 

@Alan2022 You're welcome. Glad it helped you to look into right direction!


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

1 best response

Accepted Solutions
best response confirmed by Alan2022 (Iron Contributor)
Solution

Hi @ganeshsanap,

 

Thank you very much for the guide. With this PS script it can already view user who open the shared file in excel.

$UserName = ""
$Password = ""
$credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName,$Password

# Set Location of Sharepoint 
$url = "https://<name>.sharepoint.com/personal/<site>"

# Connect to Sharepoint
Connect-PnpOnline $url -Credential $credential

# Get Context
$clientContext = Get-PnPContext
 
# -Url: relative path of the file
# -AsListItem: Retrieves the file and returns it as a ListItem object
$ListItem = Get-PnPFile -Url "/Documents/<filename.xlsx>" -AsListItem

# Get the File object
$targetFile = $ListItem.File
 
$clientContext.Load($targetFile)
 
$clientContext.ExecuteQuery()

# Get user who locked out the file
$User = $targetFile.LockedByUser
 
$clientContext.Load($User)
 
$clientContext.ExecuteQuery()

if($User.Title){
    $User.Title
}
else{
    Write-Host "No User found!"
}
 
Disconnect-PnPOnline

 

Cheers :thumbs_up::thumbs_up::thumbs_up:.

 

View solution in original post