I have a text file called "file.txt" with an output like below
Ethernet4
vEthernet
Ethernet
Ethernet
Public
Is there any methord in powershell to check , whether the name vEthernet is first in order of the output file ?
I have a text file called "file.txt" with an output like below
Ethernet4
vEthernet
Ethernet
Ethernet
Public
Is there any methord in powershell to check , whether the name vEthernet is first in order of the output file ?
To extract the first element of an array you can use the brackets with 0 [0] like that :
$myArray = @('Ethernet4', 'vEthernet', 'Ethernet', 'Ethernet', 'Public')
$myArray[0]
so if you want to test the first element, you can use a if :
if($myArray[0] -eq 'vEthernet') {
Write-Host 'YES'
} else {
Write-Host 'NO'
}
Better answer for your particular problem :
Since your input comes from a file, if you need to read only the first line and not more :
$result = Get-Content -Path '.\file.txt' -TotalCount 1
if($result -eq 'vEthernet') {
Write-Host 'YES'
} else {
Write-Host 'NO'
}