2011-04-04 63 views
1

我想自定義的母版適用於所有站點的所有站點環境沿着應用的SharePoint Foundation母版,以使用SharePoint PowerShell中

  1. http://sharepoint/
  2. http://sharepoint/site1
  3. http://sharepoint/site1/1
  4. 行認爲http://sharepoint/site2/1

我想要能夠使用powershell將自定義masterpage應用到每個站點。我知道使用

$web = Get-SPWeb http://sharepoint 
$web.CustomMasterUrl = "/_catalogs/masterpage/custom_v4.master" 
$web.Update() 

任何人都可以請所有的網站請循環幫忙。

回答

0

您需要的URL管陣列Foreach-Object

'http://sharepoint/', 
'http://sharepoint/site1', 
'http://sharepoint/site1/1', 
'http://sharepoint/site2/1' | Foreach-Object { 
    $web = Get-SPWeb $_ 
    $web.CustomMasterUrl = "/_catalogs/masterpage/custom_v4.master" 
    $web.Update() 
} 

或做在命令行式風格:

$urls = 'http://sharepoint/', 'http://sharepoint/site1', 'http://sharepoint/site1/1', 'http://sharepoint/site2/1' 

foreach($url in $urls) { 
    $web = Get-SPWeb $url 
    $web.CustomMasterUrl = "/_catalogs/masterpage/custom_v4.master" 
    $web.Update() 
} 
+0

感謝stej,是否有可能通過僅提供頂級站點http:// sharepoint來遍歷每個站點?我不知道任何網站名稱 – 2011-04-04 04:17:18

+0

是否有任何返回網站名稱列表的命令?我不知道SharePoint幾乎沒有任何內容.. – stej 2011-04-04 04:27:27

+0

@DiverDan你應該可以查詢SPSite實例AllWebs集合 – Roman 2012-05-26 04:12:43

0

,如果你想在主應用到整個網站集試試這個:

foreach ($site in get-spsite -url http://sharepoint*) { 

    $web = Get-SPWeb $site 
    $web.CustomMasterUrl = "/_catalogs/masterpage/custom_v4.master" 
    $web.Update() 

} 

欲瞭解更多關於get-spsite的信息,你可以閱讀這篇文章sharepoint automation。希望有幫助!

+0

感謝empo,什麼是$ site,就像var一樣?我需要在foreach循環之前將$ site設置爲任何東西 – 2011-04-04 06:00:32

+0

$ site是循環中的當前$站點。這是foreach語法。你可以寫成:'get-spsite -url http:// sharepoint * | %{...}'我是immagine,在大括號內使用$ _代替$ site。 – 2011-04-04 07:11:02

0

我不會依賴網站的簡單網址定位。我想你想要的是:

$site = Get-SPSite "http://localhost" 
$site.AllWebs | foreach-object { ` 
       $_.CustomMasterUrl = "/_catalogs/masterpage/custompagename.master";  
       $web.Update() 
} 

AllWebs屬性返回網站集中的所有網站。如果你確實使用了變體,你可能希望將它們從列表中以某種方式排除?{$ _。Name-like'en-us'}並在foreach管道之前進行管道操作。