SharePoint Online - PowerShell Script to Get Personal Views of List For All users of the Site

%3CLINGO-SUB%20id%3D%22lingo-sub-1458113%22%20slang%3D%22en-US%22%3ESharePoint%20Online%20-%20PowerShell%20Script%20to%20Get%20Personal%20Views%20of%20List%20For%20All%20users%20of%20the%20Site%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1458113%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20looking%20for%20an%20advice%20in%20terms%20of%20retrieving%20Personal%20views%20of%20user%20on%20list.%20This%20has%20to%20done%20for%20all%20users%20in%20the%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20onprem%26nbsp%3B%20we%20could%20impersonate%20the%20user%20and%20get%20the%20desired%20outcome.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewrite-host%3CBR%20%2F%3Ewrite-host%20%22User%20object%20Retrieved%20for%20%3A%20%22%20%24user.UserLogin%3C%2FP%3E%3CP%3E%24token%20%3D%20%24user.UserToken%3B%3C%2FP%3E%3CP%3E%24impersonatedSite%3D%20New-Object%20Microsoft.SharePoint.SPSite(%24web.Url%2C%20%24token)%3B%3C%2FP%3E%3CP%3E%24impersonatedWeb%20%3D%20%24impersonatedSite.OpenWeb()%3B%3C%2FP%3E%3CP%3Ewrite-host%20%22Impersonated%20Web%20Url%20%3A%20%22%20%24impersonatedWeb.Url%3C%2FP%3E%3CP%3E%24splist%3D%24impersonatedWeb.Lists%5B%24listName%5D%3CBR%20%2F%3E%3CBR%20%2F%3E%24allPrivateViews%20%3D%20%40()%3CBR%20%2F%3Eif(%24splist%20-ne%20%24null)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eforeach(%24view%20in%20%24splist.Views)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eif(%24view.PersonalView)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24out%20%3D%20new-object%20psobject%3CBR%20%2F%3E%24out%20%7C%20add-member%20noteproperty%20-name%20%22User%20Login%22%20-value%20%24user.UserLogin%3CBR%20%2F%3E%24out%20%7C%20add-member%20noteproperty%20-name%20%22View%20Title%22%20-value%20%24view.Title%3CBR%20%2F%3E%24allPrivateViews%2B%3D%24out%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20do%20this%20in%20SharePoint%20Online.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ERavi%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1458113%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Hi All,

 

I am looking for an advice in terms of retrieving Personal views of user on list. This has to done for all users in the site.

 

In the onprem  we could impersonate the user and get the desired outcome.

 

write-host
write-host "User object Retrieved for : " $user.UserLogin

$token = $user.UserToken;

$impersonatedSite= New-Object Microsoft.SharePoint.SPSite($web.Url, $token);

$impersonatedWeb = $impersonatedSite.OpenWeb();

write-host "Impersonated Web Url : " $impersonatedWeb.Url

$splist=$impersonatedWeb.Lists[$listName]

$allPrivateViews = @()
if($splist -ne $null)
{
foreach($view in $splist.Views)
{
if($view.PersonalView)
{
$out = new-object psobject
$out | add-member noteproperty -name "User Login" -value $user.UserLogin
$out | add-member noteproperty -name "View Title" -value $view.Title
$allPrivateViews+=$out;
}
}

 

Is there a way to do this in SharePoint Online.

 

Thanks

Ravi 

0 Replies