2011-12-08 8 views
1

PowerShellコマンドSPをruningて: http://blogs.msdn.com/b/opal/archive/2010/04/13/generate-sharepoint-2010-sitemap-with-windows-powershell.aspxは、私はこの例から、PowerShellコマンドを使用してサイトマップを作成しようとしています2010

私の行動:私は、私は開いたNew-SPSiteMap

という名前のファイルにコードをコピー

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 
:PowerShellは私が手にエラーがある

New-SPSiteMap –Url http://centerportal –SavePath C:\inetpub\wwwroot\wss\VirtualDirectories\80\sitemap.xml 

を書き、あなたが関数を含むスクリプトを実行する必要が利用可能New-SPSiteMap機能を持たせるために

答えて

2

:Alliteratively

& .\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 $SavePath 
+0

何それはRUではありませんあなたがコードに私はファイル内に入れなければならないサイトに書き留めることができる場合サイトマップを作成していない – user554672

+0

は、答えにスクリプトの内容をコピー... – Stefan

+0

私は PS C:\>。\ New- SPSiteMap.ps1 -Url http:// centerportal/-SavePath C:\ sitemap.xml とエラーが発生する 「New-Xml」という用語は、コマンドレット、関数、スクリプト ファイルの名前として認識されません。操作可能なプログラム。名前のスペルを確認するか、パスに が添付されている場合は、パスが正しいことを確認してから、もう一度やり直してください。 C:\ New-SPSiteMap.ps1:11 char:16 + $ list |新-XML <<<< -RootTag urlset -ItemTag URL -ChildItems LOC -SavePath $関数savepath + CategoryInfo:ObjectNotFound:(新-XML:文字列)[]、CommandNotF oundException + FullyQualifiedErrorId:CommandNotFoundExcepti – user554672

関連する問題