在PowerShell中按GUID查询SharePoint XML数据
我有一个很大的XML文件。它包含我的SharePoint 2010迁移检查日志(我们正在为07到10的迁移做好准备)。我对显示所有缺失的Web部件的位置的部分感兴趣,特别是它们的URL。我一直在尝试用PS SP10工具发现的每个guid识别相关的站点URL。我对Powershell比较陌生,很好奇是否有一种简单的方法来获取数据在PowerShell中按GUID查询SharePoint XML数据,xml,sharepoint,powershell,migration,Xml,Sharepoint,Powershell,Migration,我有一个很大的XML文件。它包含我的SharePoint 2010迁移检查日志(我们正在为07到10的迁移做好准备)。我对显示所有缺失的Web部件的位置的部分感兴趣,特别是它们的URL。我一直在尝试用PS SP10工具发现的每个guid识别相关的站点URL。我对Powershell比较陌生,很好奇是否有一种简单的方法来获取数据 get-childitem R:\testfile.xml | select-string -pattern "c7843aae-4c86-8206-0125-d0011
get-childitem R:\testfile.xml | select-string -pattern "c7843aae-4c86-8206-0125-d00117cb461c"
返回每个实例,例如:
testfile.xml:112644:
但是,我需要与Web部件关联的URL
$xml.databases.Database[1].Site[0].Webs.Web
(这与testfile相同)
存储此信息的级别(提供ID、URL、LanguageId、TemplateName、TemplateId、功能、EventReceiveAssembly、WebParts、CustomListView、SetupFiles)
有没有办法组合这些命令?我只需要找到该guid的每个实例及其关联网站的URL。感谢您的帮助,我是PowerShell的新手,我想它可能可以帮助我不必亲自查看(gui的实例显示了大约85次)就可以阅读本文档
非常感谢你。还有,长期潜伏者,第一次海报
尼克
您可以执行以下操作:
$xml.SelectNodes("//Web") | %{
if($_.SelectNodes("./WebParts/WebPart") | ?{ $_.id -eq "f6bfd4dd-e6b5-7cb0-e080-e7674fcdd856" } ){
$_.Url
}
}
$file = "file.xml"
Get-Content $file -AsXml -XPath "//Web[WebParts/WebPart//@*[1][contains(.,'f6bfd4dd-e6b5-7cb0-e080-e7674fcdd856')]]/@*[2]"
在这里,我正在查找guid
f6bfd4dd-e6b5-7cb0-e080-e7674fcdd856
,它返回/ssp/admin/xxxxa
,Web的url您可以使用此代理函数
Function Get-Content {
<#
***************************************************************************
--------------------8<-----------------------------------------
Ajout de deux nouveaux paramètres pour simplifier
le traitement des fichiers XML: [-AsXml] [-XPath <String>]
Attention: l'expression Xpath est sEnSiBlE à La cAsSe
Walid toumi
--------------------8<-----------------------------------------
PS> # Exemples d'utilisation:
PS> $file = "$PSHOME\types.ps1xml"
PS> $u = cat $file -As | Select-Xml -XP "//ScriptProperty" | Select -Expand Node
PS> $u
PS> $Xml = Get-Content $file -AsXml
PS> $Xml.Types.Type[1..10]
PS> Get-Content $file -AsXml -XPath "//Type[contains(Name,'Xml')]/Name"
**************************************************************************
.ForwardHelpTargetName Get-Content
.ForwardHelpCategory Cmdlet
#>
[CmdletBinding(DefaultParameterSetName='Path', SupportsTransactions=$true)]
param(
[Parameter(ValueFromPipelineByPropertyName=$true)]
[System.Int64]
${ReadCount},
[Parameter(ValueFromPipelineByPropertyName=$true)]
[System.Int64]
${TotalCount},
[Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
[System.String[]]
${Path},
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
[Alias('PSPath')]
[System.String[]]
${LiteralPath},
[System.String]
${Filter},
[System.String[]]
${Include},
[System.String[]]
${Exclude},
[System.String]
${XPath},
[Switch]
${Force},
[Switch]
${AsXml},
[Parameter(ValueFromPipelineByPropertyName=$true)]
[System.Management.Automation.PSCredential]
${Credential})
begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-Content', [System.Management.Automation.CommandTypes]::Cmdlet)
$cmd = ''
if($AsXml) {
[void]$PSBoundParameters.Remove('AsXml')
$cmd += ' | ForEach-Object {$fx=@()} {$fx+=$_} {$fx -as [Xml]}'
if($XPath) {
[void]$PSBoundParameters.Remove('XPath')
$cmd += ' | Select-Xml -XPath $XPath | Select -expand Node'
}
}
$ScriptCmd = [ScriptBlock]::Create(
{ & $wrappedCmd @PSBoundParameters }.ToString() + $Cmd
)
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
process
{
try {
$steppablePipeline.Process($_)
} catch {
throw
}
}
end
{
try {
$steppablePipeline.End()
} catch {
throw
}
}
}
或者干脆
Select-Xml -Path $file -XPath '//Web[WebParts/WebPart/@Id = "f6bfd4dd-e6b5-7cb0-e080-e7674fcdd856"]/@Url' | % { $_.node.'#text' }
你能举一个你正在使用的xml的例子吗?确保这是xml的文件结构
(这个级别包含站点URL)(这个级别有用于标识部件的ID)
如果你想看到实际的代码,请告诉我,我必须在某处有一个文件主机。感谢您的帮助编辑您的问题并附加一个具体的xml,可能来自testfile.xml(与上面的不同)。相关代码将有助于添加一些testfile.xml,编辑掉一些信息以适应这里。到目前为止谢谢。哇,真是太棒了。非常感谢你。真的让我很开心。有可能也抓住伯爵吗?我用你的代码试过了,但似乎不能同时抓住它们。再次感谢你!非常感谢。奇怪的是,如果我也想获取关联的count属性,那么我就可以获取URL和count,我该怎么做呢?我发现XML和powershell很难学习。非常感谢你们的时间和帮助
Select-Xml -Path $file -XPath '//Web[WebParts/WebPart/@Id = "f6bfd4dd-e6b5-7cb0-e080-e7674fcdd856"]/@Url' | % { $_.node.'#text' }