0

我在这里使用 SP 2010 Foundation 中的 NewWebPage xml 命令遇到了一个奇怪的问题。下面的代码工作不工作

cls
Write-Host "Production Manager v8.0 Deployment Utility" -ForegroundColor red
Write-Host ""

#Starting the script. Lets see if we can find the configuration and map files first.
Write-Host -NoNewline "Checking for the Configuration.xml, PageMap.xml and  PageTemplate.xml files: " -ForegroundColor white
if((Test-Path "Configuration.xml") -and (Test-Path "PageMap.xml") -and (Test-Path "PageTemplate.xml"))
{
     Write-Host "FOUND" -ForegroundColor green
}
else
{
    Write-Host "NOT FOUND" -ForegroundColor red
    Write-Host "Check for the necessary files and try again."
    Write-Host ""
    Write-Host ""
    exit
}

Write-Host "Reading Configuration.xml"
[xml]$Configuration = Get-Content Configuration.xml
Write-Host "Reading PageMap.xml"
[xml]$PageMap = Get-Content PageMap.xml

Write-Host "Reading from Production Manager Site:    "$Configuration.Configuration.SiteConfiguration.SiteURL



#Some variables necessary for the loop
$pageCreationLoopIterations = 0
$pageLayout = ""
$pageTitle = ""
$createPageCommand = '<?xml version="1.0" encoding="UTF-8"?><Method ID="0,NewWebPage"><SetList Scope="Request">' + $productionManagerLibrary.ID + '</SetList><SetVar Name="Cmd">NewWebPage</SetVar><SetVar Name="ID">New</SetVar><SetVar Name="Type">WebPartPage</SetVar><SetVar Name="WebPartPageTemplate">' + $pageLayout + '</SetVar><SetVar Name="Overwrite">true</SetVar><SetVar Name="Title">MyPage</SetVar></Method>';

#Beginning the loop
Write-Host "Running through the PageMap file"

foreach($Page in $PageMap.Pages.Page)
{
     $web = Get-SPWeb $Configuration.Configuration.SiteConfiguration.SiteURL
     $productionManagerLibrary = $web.Lists | Where { $_.Title -eq "Production Manager" }
     $pageName = if($Page.SelectSingleNode("PageName")) { $Page.PageName } else {      $Configuration.Configuration.PageConfiguration.DefaultPageName }
     $pageLayout = if($Page.SelectSingleNode("PageLayout")) { $Page.PageLayout } else { $Configuration.Configuration.PageConfiguration.DefaultPageLayout }

     Write-Host 'Creating Page ' $pageName
     $web.ProcessBatchData($createPageCommand)

}

但是每次我运行它时这个都可以正常工作:

$url = "http://mpm8/mpm";
$listname = "Production Manager"
$web = Get-SPWeb $url
$pagesLibrary = $web.Lists | Where { $_.Title -eq "Production Manager" }
$pageLayout = 8
$cmd = '<?xml version="1.0" encoding="UTF-8"?><Method ID="0,NewWebPage"><SetList Scope="Request">' + $pagesLibrary.ID + '</SetList><SetVar Name="Cmd">NewWebPage</SetVar><SetVar Name="ID">New</SetVar><SetVar Name="Type">WebPartPage</SetVar><SetVar Name="WebPartPageTemplate">' + $pageLayout + '</SetVar><SetVar Name="Overwrite">true</SetVar><SetVar Name="Title">MyPage</SetVar></Method>';
$web.ProcessBatchData($cmd)

我真的看不出两个脚本之间有什么不同。我运行第一个错误是:

<Result ID="0,NewWebPage" Code="-2130575350">
<ErrorText>Invalid URL Parameter.

The URL provided contains an invalid Command or Value. Please check the URL again.   </ErrorText></Result>

你能帮我解决这个问题吗?也许我不能在 foreach 循环中运行这个东西?:(

谢谢!

4

1 回答 1

0

您首先设置了 $createPageCommand(在循环之前),然后设置了它需要的变量(在循环中)。

如果您在 ISE 中运行它并逐步执行(即调试它),您可以看到变量及其值,否则只需在运行循环时将变量的值发送到屏幕以确保其设置正确。

因此,在您的示例中,将 $createPageCommand 放在循环中并在设置 $productionManagerLibrary 之后。然后,在 $web.ProcessBatchData($createPageCommand) 之前,您应该发出 $createPageCommand 的值以确保它正常。

我只是盯着它而不运行它,但请我们知道这是否是原因!

于 2012-12-17T06:06:50.550 回答