Skip to main content

Hide-SPView

This cmdlet sets a view to hidden.
Parameters: SiteCollection url.
Edit $listUrl and $viewUrl to your own values.

param([string]$url)
param([string]$url)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function Get-SPSite([string]$url) {
    New-Object Microsoft.SharePoint.SPSite($url)
}
function Hide([string]$url) {
    $SPSite = Get-SPSite $url
 $listUrl = "/Lists/Tasks";
 $viewUrl = "Lists/Tasks/byowner.aspx";
    foreach($oWeb in $SPSite.AllWebs)
 {
        Write-Host "############  ###################";
        Write-Host "Web: " $oWeb.Url;
        
        [Microsoft.SharePoint.SPList]$list = $null;
        [Microsoft.SharePoint.SPView]$spView = $null;
        
        try {
            $list = $oWeb.GetList("$($oWeb.Url)$($listUrl)");
       }
    catch [Exception] { 
            Write-Host "The list does not exist" -foreground red;
            $oWeb.Dispose();
            continue;
       }
        
       try {
            $spView = $oWeb.GetViewFromUrl($viewUrl);
            $spView.Hidden = $true;
            $spView.Update();             
    }
    catch [Exception] { 
            Write-Host "The view does not exist" -foreground red;
            $oWeb.Dispose();
            continue;
       }
       Write-Host "View: " $spView.Title -foreground blue;
       Write-Host "View hidden: " $spView.Hidden -foreground blue;
       Write-Host "ParentList: " $spView.ParentList -foreground green;
       $oWeb.Dispose();
       Write-Host "############  ###################";
 } 
 $SPSite.Dispose()
}

Hide -url $url

Comments

Popular posts from this blog

The form cannot be submitted because of an error

Problem I created a reusable approval workflow in SharePoint Designer 2010. I initiated the workflow. Then when I filled in the Assigned To field I got an error pop up saying: "The form cannot be submitted because of an error". Solution Uninstall the KB2553322 for SharePoint Designer. I didn't uninstall KB2553322 for Microsoft Office. Restart SharePoint Designer. Recreate the workflow.

Enable PowerShell commandlets for SharePoint 2013 in PowerShell ISE

Open the PowerShell ISE and create a profile by running the following code: if (!(test-path $profile.AllUsersAllHosts)) { new-item -type file -path $profile.AllUsersAllHosts-force } Open the newly created profile with the following command: psEdit $profile.AllUsersAllHosts The profile will be open in the PowerShell ISE. Add the following code to the profile: (If the profile for some reason doesn't open then you can get it here: C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1) if ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } Save the profile. Next time you open the PowerShell ISE you will have all the Microsoft.SharePoint.PowerShell commandlets.

Error when running Register-SPAppPrincipal

Problem You get the error, "Cannot find an SPWeb object with Id or Url" , when trying to get the RootWeb of the SPSite object when you register a new app with the Register-SPAppPrincipal PowerShell cmdl. Register-SPAppPrincipal -NameIdentifier $appPrincipalIdentifier -Site $site.RootWeb -DisplayName 'ProviderHostedApp' The cause could be The user who is running the script is NOT a farm administrator. Fix the problem Add the user to the farm administrator group