立即将 SPWeb 更改为特定路径



我想更改我的 PowerShell 脚本,以立即在网站集中为特定网站定义$spWeb值,而不是经历多个foreach循环。

可能吗?

代码示例:

$url = "http://testweb.com"
$siteCollection = Get-SPSite $url 
$WebApp = $siteCollection.WebApplication 
$url = $url+"/sites/site1"
foreach ($Site in $WebApp.Sites) 
{
  foreach($spWeb in $Site.AllWebs) 
  { 
        if ($spWeb.URL -eq $url)
        {
//Skip previous foreach loops and declare $spWeb value with a fixed URL here
            $users = $spWeb.SiteUserInfoList
            $groups = $users.Items
            $RList = $spWeb.Lists["Records"]
            $RCount = 0
            #GET Records
            #$outputnewwebtext = "GET Records in $($spWeb.URL)"
            #$outputnewwebtext |Tee-Object MRCE_Records.txt -Append
            $query =  New-Object Microsoft.SharePoint.SPQuery 
            $query.Query = '<Where><Eq><FieldRef Name="ContentType" /><Value Type="Computed">Item</Value></Eq></Where>'
            $query.ViewAttributes = "Scope='RecursiveAll'";
            $records = $Rlist.GetItems($query)
            for ($intIndex =$records.Count - 1; $intIndex -gt -1; $intIndex--)
            {
                $RCount ++
            }
            $outputnewwebtext = "Records in $($spWeb.URL): $RCount`n"
        }
   }
}

尝试 Get-SPWeb 命令。

Get-SPWeb http://sp10/sites/team1

最新更新