Oct 11 2022 05:47 PM
Hi Community,
Is there a way to list all the user active session who opened the shared excel file in sharepoint?
Thanks.
Oct 12 2022 01:02 AM
@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.
Oct 12 2022 07:37 PM
SolutionHi @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:.
Oct 12 2022 10:04 PM
@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.