Thanks in Advance,
I am quite new to the PowerShell. Any help will be thankful.
Requirement:
1) if there is no value present in the Environment filed <Environment></Environment>. Need to print as "No Environment Present" .
2) if there is value present in the Environment filed <Environment>P01</Environment>. Need to print as " Environment Present" .
I am having a XMl file(File is attached). I need to print as "No Environment Present" if there is no value present in the Environment filed. I have wrote a small script as below. Even though the <Environment></Environment> filed doesn't contain any data. It will print as "Environment Present".
There is no valid data is present in the $Envmnts variable PowerShell will assume there is data is stored to $Envmnts due to the white space. Always the output will be "Environment Present". Please help me.
Script
[xml]$xmlKibana=get-content -path C:\Work_test\KibanaCode.xml
$Envmnts=$xmlKibana.Kibanadecode.KB.Environment
$Envmnts
if($Envmnts -eq $null)
{
Write-host "No Environment Exist"
}
else
{
Write-host "Environment Present"
}
===========================
Sample Xml file
<?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>PRD1</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>
======================================================================