magritton
11/15/2016 - 8:57 PM

The powershell script lists all the personal views of a user and gives the option to delete is if needed.

The powershell script lists all the personal views of a user and gives the option to delete is if needed.

$webSiteURL = "https://xxxx" 
$loginNamePart = "socha"
$listName = "CATS Items"
$viewToDelete = "NA" #NA for no delete

$web = Get-SPWeb $webSiteURL
$i = 0
foreach ($user in $web.AllUsers) {

if($user.UserLogin -like "*$loginNamePart*")
{
	$userSite = New-Object Microsoft.SharePoint.SPSite($web.Site.ID, $user.UserToken)
	#$user | ft UserLogin, UserToken
	$userWeb = $userSite.OpenWeb($web.ID)
	$list = $userWeb.Lists[$listName]
	foreach ($view in $list.Views) {
		if ($view.PersonalView) {
			$view.Title
			$view.Title | out-file F:\temp\personalView.txt -append
			if($view.Title -eq $viewToDelete)
			{
				#$list.Views.Delete($view.ID)
				
				break
			}
			$i++
		}
	}
}#end if user

}#end for
$i