Update Hidden View with PowerShell

Here is quick fix for an issue where AllItems view was set to blank and was set to hidden.  Here is how I fixed it.  Nothing fancy just some old Server OM calls in PowerShell.

First you have to list all the views to find it out what’s going wrong and put it in a list.

$SiteUrl = https://portal.contoso.com     
$ListUrl = "Discussions List"            

$Databases = @();
       
$Web = Get-SPWeb -Identity $SiteUrl            
if ($Web -ne $null)            
{
    $List = $Web.Lists[$ListUrl]
    foreach($view in $List.Views)
    {
        $ViewFile = $targetUrl.GetFile($view.Url)
        $Viewobj = New-Object PSObject
        Add-Member -input $Viewobj noteproperty 'ID'  $view.ID
        Add-Member -input $Viewobj noteproperty 'Title'  $view.Title
        Add-Member -input $Viewobj noteproperty 'CreatedBy'  $ViewFile.Author
        Add-Member -input $Viewobj noteproperty 'Modified' $ViewFile.TimeLastModified 
        Add-Member -input $Viewobj noteproperty 'ModifiedBy' $ViewFile.ModifiedBy 
        Add-Member -input $Viewobj noteproperty 'CreatedOn' $ViewFile.TimeCreated  
        Add-Member -input $Viewobj noteproperty 'Private' $view.PersonalView  
        Add-Member -input $Viewobj noteproperty 'Url' $view.Url  
        Add-Member -input $Viewobj noteproperty 'Hidden' $view.Hidden  
        $Databases += $Viewobj
          
    }
    #Export If Needed.        
    #$Databases  | Out-File C:\View.txt

}
#Select the View and Click OK in GridView
$aBadView= $Databases | Out-GridView -PassThru
$aBadView.ID

Now You have the View ID you have do it like below

$ID = [guid]("0b57d149-dbcc-4652-b72f-2fa024238301")    #$ID = [guid]($aBadView.ID)
$BadView = $List.Views[$ID]
$BadView.Title = "Subject"
$BadView.Hidden = $false
$BadView.Update()

Run the first part of script again to verify.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s