In this script I would like to show how we can perform XML search by passing an input parameter.
Sample xml file to work with the example
Sample xml file to work with the example
- <Employees>
- <Employee>
- <Name>TestName</Name>
- <Age>32</Age>
- <Location>Hyderabad</Location>
- </Employee>
- <Employee>
- <Name>TestName1</Name>
- <Age>29</Age>
- <Location>Hyderabad</Location>
- </Employee>
- <Employee>
- <Name>TestName3</Name>
- <Age>45</Age>
- <Location>Rajahmundry</Location>
- </Employee>
- </Employees>
Power shell script
- cls
- function XmlOperations
- {
- param (
- [Parameter(Mandatory)]
- [string] $EmployeeName
- )
- $xml = [xml](Get-Content C:\sample.xml)
- $xml.Employees.Employee | where { $_.Name -like "*$EmployeeName*" }
- }
- XmlOperations
No comments:
Post a Comment