我有一个脚本,可以获取我所需的有关SharePoint场的所有信息:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()
foreach ($websvc in $websvcs) {
write-output "Web Applications"
write-output ""
foreach ($webapp in $websvc.WebApplications) {
write-output "Webapp Name -->"$webapp.Name
write-output ""
write-output "Site Collections"
write-output ""
foreach ($site in $webapp.Sites) {
write-output "Site URL --> -->" $site.URL
write-output ""
write-output "Websites"
write-output ""
foreach ($web in $site.AllWebs) {
write-output "Web URL --> --> -->" $web.URL
write-output ""
write-output "Lists"
write-output ""
foreach ($list in $web.Lists) {
write-output "List Title --> --> --> -->" $list.Title
write-output ""
}
foreach ($group in $web.Groups) {
write-output "Group Name --> --> --> -->" $group.Name
write-output ""
foreach ($user in $group.Users) {
write-output "User Name --> --> --> -->" $user.Name
write-output ""
}
}
}
}
}
}
我想将输出生成为XML文件,然后将xml文件连接至HTML,并为其创建站点供经理使用
我该怎么做 ?
谢谢您的帮助 !
最佳答案
我要说的是,您有2种选择应该相当容易:
最简单的方法是建立一个字符串作为xml,而不是使用write-output。
$procs = get-Process
$xml = "<xml>"
foreach($proc in $procs)
{
$xml += "<process name='" + $proc.Name + "' id='Proc_"+$proc.Id+"'>"
$xml += "<modules>"
foreach($module in $proc.Modules)
{
$xml += "<module>"
$xml += $module.ModuleName
$xml += "</module>"
}
$xml += "</modules>"
$xml += "</process>"
}
$xml += "</xml>"
$xml | out-File -FilePath c:\temp\proc1.xml
或者-您可以将输出构建为psobject,然后尝试使用PowerShell cmdlet之一将其输出为XML。可能是更健壮的方法,因为您随后可以通过管道使用其他PowerShell cmdlet。看起来像这样:
$procs = get-Process
$processObject = @()
foreach($proc in $procs)
{
$procInfo = new-Object PSObject
$procInfo | add-Member NoteProperty -Name "Process" $proc.Name
$procInfo | add-Member NoteProperty -Name "ID" $proc.Id
$moduleInfo = @()
foreach($module in $proc.Modules)
{
$moduleInfo += $module.ModuleName
}
$procInfo | add-Member NoteProperty -Name "Module" $moduleInfo
$processObject += $procInfo
}
$processObject | export-Clixml c:\temp\procs.xml
关于xml - 使用Powershell编写xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8134203/