0

Trying to get access the folder and files within the style library using PowerShell in my SP 2013 env.

 Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction 
 SilentlyContinue
 cls

 $weburl= "https://mydms.prod.com/sites/dmsHome/"
 $sitee = Get-SPSite $weburl
 $web = Get-SPWeb  $weburl

 #$file =Get-Item $FilePath
 $stylelib  =  $web.lists["Style%20Library"]

 $stylelib.name

 $stylelib.title
 pause
 foreach ($file in $folder.Files) 
  {
      Write-Host "inside foreach,...."
      $file.Url + "---" + $file.name
      pause
  }
 pause
3
  • Try to run without the html encode for a blank space (%20) like $web.lists["Style Library"] Jul 7 '15 at 13:48
  • Or, try to actually assign $folder a value before trying to iterate over it Jul 7 '15 at 13:48
  • And i don't think you need to get the spsite object to get the web, just go for the web directly. Jul 7 '15 at 13:49
1

The following will iterate all files in the root of your style library.

Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
cls

$web = Get-SPWeb "https://mydms.prod.com/sites/dmsHome/"

$stylelib  =  $web.lists["Style Library"]

write-host "Title:"$stylelib.title

foreach ($file in $stylelib.RootFolder.Files)
{
  Write-Host "inside foreach,...."
  $file.Url + "---" + $file.name  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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