使用powershell编写xml
我有一个脚本,可以获取有关我的 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 并创建一个网站供经理使用,
我该怎么做?
感谢您的帮助!
i have a script that get all the info i need about my SharePoint farm :
[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 ""
}
}
}
}
}
}
i want to make the output to an XML file and then connect the xml file to HTML and make a site of it for manager use
how can i do it ?
thanks for the help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想说你有两个选择,应该相当简单:
最简单的方法是,不使用写输出,而是构建一个字符串作为你的 xml。
或者 - 您可以将输出构建为 psobject,然后尝试使用 PowerShell cmdlet 之一将其输出为 XML。可能是更可靠的方法,因为您可以通过管道使用其他 PowerShell cmdlet。那看起来像这样:
I would say you have 2 options that should be fairly easy:
The simplest way would be, instead of using write-output, build up a string as your xml.
Or - you could build up your output as a psobject and then try one of the PowerShell cmdlets to output it as XML. Probably the more robust way to do it, since you can then use other PowerShell cmdlets via the pipeline. That would look something like this:
如果要将对象输出为 XML,可以尝试 Export-Clixml 命令。例如 :
如果您想要直接生成 HTML 页面,可以使用命令 ConvertTo-Html :
您可以使用 head、title、body 和 CSS 自定义后面的命令。
If you want to output the objects to XML, you can try the Export-Clixml command. For example :
If you want directly an HTML page, you can use the commande ConvertTo-Html :
You can customize the later command with head, title, body and CSS.
以下是 iHunger 的答案的更新:
请参阅使用 PowerShell 读取、更新和写入 XML 文档
Here is an update to iHunger's answer:
See Reading, updating and writing XML document with PowerShell