locked
running PowerShell against all webs in a SharePoint web application RRS feed

  • Question

  • Hi

    I have this script which works just fine against a site collection

    foreach ($web in (get-spsite -Identity "http://intranet-pp/sites/ict").allwebs)
    {
        do {
           $web.ExcludeFromOfflineClient = $true
           $web.Update()
        } until ($web.ExcludeFromOfflineClient -eq $true)
    }

    Problem is I have hundreds of site collections to run this against so I have been trying to edit it to parse through all the site collections in a given web application - but I can't get it to work -

      # Get Webapplicton

    $SPWebApp = Get-SPWebApplication "http://intranetwa-pp/"

    # Get all sites

    $SPSites = $SPWebApp | Get-SPsite -Limit all 

    foreach($SPSite in $SPSites){

      # Get all websites
      $SPWebs = $SPSite | Get-SPWeb -Limit all
      
    foreach($SPList in $SPweb.lists){
      
      
        do {
           $web.ExcludeFromOfflineClient = $true
           $web.Update()
        } until ($web.ExcludeFromOfflineClient -eq $true)


    }


    }


    It doesn't error - it just doesn't work

    If anyone can help - would be great

    cheers

    jonj


    • Edited by jonjames Wednesday, January 30, 2019 11:56 AM typo
    Wednesday, January 30, 2019 11:54 AM

All replies

  • You need to debug the code a line at a time to see where it is failing.  You code needs to check each call to be sure that there is a result.


    \_(ツ)_/

    Wednesday, January 30, 2019 3:14 PM
  • OK - after much head-scratching I got it to work

    fyi:

    # Get Webapplicton
    
    $SPWebApp = Get-SPWebApplication "http://intranetwa-pp/"
    
    # Get all sites
    
    $SPSites = $SPWebApp | Get-SPsite -Limit all 
    
    foreach($SPSite in $SPSites){
    
      # Get all websites
      $SPWebs = $SPSite | Get-SPWeb -Limit all
      
    foreach ($SPWeb in $SPWebs)  {do {
      
      
         
           $SPWeb.ExcludeFromOfflineClient = $true
           $SPWeb.Update()
    	
    	}  until ($SPWeb.ExcludeFromOfflineClient -eq $true)
    	
    							}	
    	}
    	

    Wednesday, January 30, 2019 4:08 PM