Thanks in advance.
I need to write a powershell script to check whether the KB is present in the attached XML file. I am quite new to the PowerShell world. But i tried in my own ways unfortunately not getting succeed. The script is checking few conditions after and before this requirement. I hope the rest of the script is working fine with the help of few good peoples. Can any one help me on this
Requirement:
- Check the KB portion is present in the file
- If Kb portion is not present write- host " KB not present"
- If kb portion is present continue the script
Sample Script.
=============================================
$xmlpath = "C:\Work_test\KibanaCode.xml"
$p=Test-path $xmlpath
switch($true)
{
(!$p)
{
write-host"File Not Exist"
}
($p)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
[xml]$xmlKibana=get-content -path C:\Work_test\KibanaCode.xml
$xmlKibana.Kibanadecode.KB | ForEach-Object {
if ($_.Environment) { $status = "Present" }
else { $Status = "not present" }
}
$Status
}
}
===============================
Sample XML with out KB
================
<?xml version="1.0" encoding="UTF-8"?>
<Kibanadecode>
<FileDetails>Kibana Code Output</FileDetails>
</Kibanadecode>
=================================
Sample XML with KB
=============================
<?xml version="1.0" encoding="UTF-8"?>
<Kibanadecode>
<FileDetails>Kibana Code Output</FileDetails>
<KB>
<ID>KB/135</ID>
<KBMachine>HTZAPP10</KBMachine>
<KBMainMachine>HAPMAIN01</KBMainMachine>
<Environment></Environment>
<Build>Windows</Build>
<StartTime>21/08/2021 09:15:01</StartTime>
<EndTime>21/08/2021 10:35:13</EndTime>
<Output>Success</Output>
<Details>
</Details>
<steps>
<step-1>
<stepname>Fis Push</stepname>
<stepcommand>Oracle.exe</stepcommand>
<Output>Success</Output>
</step-1>
<step-2>
<stepname>Block chain</stepname>
<stepcommand>Oracle.exe</stepcommand>
<Output>Success</Output>
</step-2>
</steps>
</KB>
<KB>
<ID>KB/135</ID>
<KBMachine>HTZAPP10</KBMachine>
<KBMainMachine>HAPMAIN01</KBMainMachine>
<Environment></Environment>
<Build>Windows</Build>
<StartTime>21/08/2021 09:15:01</StartTime>
<EndTime>21/08/2021 10:35:13</EndTime>
<Output>Success</Output>
<Details>
</Details>
<steps>
<step-1>
<stepname>Fis Push</stepname>
<stepcommand>Oracle.exe</stepcommand>
<Output>Success</Output>
</step-1>
<step-2>
<stepname>Block chain</stepname>
<stepcommand>Oracle.exe</stepcommand>
<Output>Success</Output>
</step-2>
</steps>
</KB>
</Kibanadecode>
===========================================================
161176-kibanacode.xml