Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data formats does PowerShell most easily read?

I'm trying to use PowerShell with SharePoint. I'd like my PowerShell scripts to load my SharePoint farm configuration from files rather than either hard coding the configuration in the scripts, or having to pass in the same parameters each time.

This the kind of information I need to store.

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

Does PowerShell easily load this data from CSV, XML, or other formats?

like image 806
Jim Avatar asked Feb 19 '26 15:02

Jim


1 Answers

Powershell has great support for XML data is it allows you to "dot" through an XML hierarchy. For example assume your data was in the following form

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

It could be accessed like so

C:\Users\jaredpar> $data = [xml](gc example.xml)
C:\Users\jaredpar> $data.Root.WebFrontEnds.ChildNodes | %{ $_.Name }
Web1
Web2
Web3
like image 165
JaredPar Avatar answered Feb 21 '26 15:02

JaredPar