首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行PowerShell命令sp 2010

运行PowerShell命令sp 2010
EN

Stack Overflow用户
提问于 2011-12-08 18:38:37
回答 1查看 1.3K关注 0票数 2

我正在尝试使用本例中的PowerShell命令创建站点地图:http://blogs.msdn.com/b/opal/archive/2010/04/13/generate-sharepoint-2010-sitemap-with-windows-powershell.aspx

我的操作:我将代码复制到一个名为New-SPSiteMap的文件中

我打开PowerShell并写道

代码语言:javascript
复制
New-SPSiteMap –Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml

我得到的错误是:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-08 19:50:51

为了使New-SPSiteMap函数可用,您必须执行包含该函数的脚本:

代码语言:javascript
复制
& .\New-SPSiteMap.ps1
New-SPSiteMap –Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml

首先,您可以将PowerShell脚本转换为可调用的“函数”,如下所示:

代码语言:javascript
复制
.\New-SPSiteMap.ps1 -Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml

您所要做的就是删除函数声明function New-SPSiteMap

代码语言:javascript
复制
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 $SavePath
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8429631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档