0

This question already has an answer here:

I'm trying to get all names of the personal views created by users for a list.

When I'm using the code

$views = $list.views
foreach($view in $views){
   Write-Host $view.Title       
}

It only lists the Public views so there is no point in using the condition $view.PersonalView.

Is there any way I can list all the views, including personal and public ones and then filter for only the personal ones?

marked as duplicate by Robert Lindgren Feb 7 '17 at 10:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

I have never tried what @gautam-sheth has suggested... It may work although I assume you are running as an admin anyway?

Anyway what does work for me is to get the SPSite object with a user token as in the following function:

function Get-SPSiteWithToken {
    param (
        [string]$spSite,
        [string]$spweb,
        [Microsoft.SharePoint.SPUserToken]$userToken,
        [string]$spList
    )
    $site = New-Object Microsoft.SharePoint.SPSite($spSite, $userToken)
    $web = $site.OpenWeb($spWeb)
    $list = $web.Lists.TryGetList($spList)
    if ($list) {
        foreach ($view in $list.views) {
            if ($view.PersonalView) {
                Write-Host $view.Title
                #Do some stuff here
            }
        }
    }
}

You then need to call it from something like:

$web = Get-SPWeb http://sharepoint/site/web
foreach ($user in $web.Users) {
    if (!$user.IsDomainGroup) {
        Get-SPSitewithToken "http://sharepoint/sites/sitecollection" "/relativeUrl/to/web" $user.UserToken "TargetListName"
    }
}
0

Try using Run with elevated priviledges as below:

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ 
        $url = "https://sitecollectionurl"
        $web = Get-SPWeb -identity $url
        $list = $web.Lists["CustomList"]
        $viewCollection = $list.Views
        foreach($view in $viewCollection)
        {
            if($view.PersonalView)
            {
                Write-host "Personal View " + $view.Title 
            }
            else
            {
                Write-host "Public View " + $view.Title 
            }
        }    
});
  • No luck, it still shows only the views created by the System Admin Account. – kaz Feb 7 '17 at 9:08

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