gpt4 book ai didi

powershell - PowerShell 最容易读取哪些数据格式?

转载 作者:行者123 更新时间:2023-12-03 17:06:17 25 4
gpt4 key购买 nike

我正在尝试将 PowerShell 与 SharePoint 结合使用。我希望我的 PowerShell 脚本从文件加载我的 SharePoint 场配置,而不是在脚本中对配置进行硬编码,或者每次都必须传递相同的参数。

这是我需要存储的信息。

WebFrontEnds: Web1, Web2, Web3
CentralAdmin: Central1
Index: Web1
ContentWebApps: http://user1, http://user2

PowerShell 是否可以轻松地从 CSV、XML 或其他格式加载这些数据?

最佳答案

Powershell 对 XML 数据有很好的支持,因为它允许您在 XML 层次结构中“点”。例如,假设您的数据采用以下形式

<Root>
<WebFrontEnds>
<Web1 />
<Web2 />
<Web3 />
</WebFrontEnds>
</Root>

可以这样访问

C:\Users\jaredpar> $data = [xml](gc example.xml)
C:\Users\jaredpar> $data.Root.WebFrontEnds.ChildNodes | %{ $_.Name }
Web1
Web2
Web3

关于powershell - PowerShell 最容易读取哪些数据格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2836644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com