Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

How to test if the Theme folder exists in $web.Folders["_themes"].subfolders

$
0
0

Here's the question - How can I test for existance of the $web.Folders["_themes"].subfolders[$themeFolderName]) folder BEFORE I assign it to $folder variable?

My code is below, and I want to list and count occurances of the MyTheme folder, which is a custom theme. I get an errror: Cannot index into a null array. on this line
$folder = @($web.Folders["_themes"].subfolders[$themeFolderName])

Any suggestions are much appreciated!


#code

if ( (Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.Powershell
}

 

$siteUrl= "http://MyWebApp"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
$themeFolderName = "MyTheme"

write-host "Counting MyTheme folder from sites and subsites" -foregroundcolor green


foreach ($site in $spWebApp.Sites) {



write-host "Site Collections URL ->" $site.URL

write-host "SubSites"

foreach ($web in $site.AllWebs) {


$count = 0

$folder = @($web.Folders["_themes"].subfolders[$themeFolderName])

if ($folder.Exists -eq $true)
{
write-host "SubSite URL --> -->" $web.URL " has a MyTheme folder"
$count++
}

 


Viewing all articles
Browse latest Browse all 8411

Trending Articles