我正在尝试使用本例中的PowerShell命令创建站点地图:http://blogs.msdn.com/b/opal/archive/2010/04/13/generate-sharepoint-2010-sitemap-with-windows-powershell.aspx
我的操作:我将代码复制到一个名为New-SPSiteMap的文件中
我打开PowerShell并写道
New-SPSiteMap –Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml我得到的错误是:
The term 'New-SPSiteMap' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ New-SPSiteMap <<<< -Url http://mossdev2010 -SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml
+ CategoryInfo : ObjectNotFound: (New-SPSiteMap:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException发布于 2011-12-08 19:50:51
为了使New-SPSiteMap函数可用,您必须执行包含该函数的脚本:
& .\New-SPSiteMap.ps1
New-SPSiteMap –Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml首先,您可以将PowerShell脚本转换为可调用的“函数”,如下所示:
.\New-SPSiteMap.ps1 -Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml您所要做的就是删除函数声明function New-SPSiteMap
param($SavePath="C:\inetpub\wwwroot\wss\VirtualDirectories\80\SiteMap.xml", $Url="http://sharepoint")
function New-Xml
{
param($RootTag="urlset",$ItemTag="url", $ChildItems="*", $SavePath="C:\SiteMap.xml")
Begin {
$xml="<?xml version=""1.0"" encoding=""UTF-8""?>
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">"
}
Process {
$xml += " <$ItemTag>"
foreach ($child in $_){
$Name = $child
$xml += " <$ChildItems>$url/$child</$ChildItems>"
}
$xml += " </$ItemTag>"
}
End {
$xml += "</$RootTag>"
$xmltext=[xml]$xml
$xmltext.Save($SavePath)
}
}
$web = Get-SPWeb $url
$list = $web.Lists | ForEach-Object -Process {$_.Items} | ForEach-Object -Process {$_.url.Replace(" ","%20")}
# excludes directories you don’t want in sitemap. you can put multiple lines here:
$list = $list | ? {$_ -notmatch "_catalogs"}
$list = $list | ? {$_ -notmatch "Reporting%20Templates"}
$list = $list | ? {$_ -notmatch "Reporting%20Metadata"}
$list | New-Xml -RootTag urlset -ItemTag url -ChildItems loc -SavePath $SavePathhttps://stackoverflow.com/questions/8429631
复制相似问题