0

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 ?

1
  • 1
    "Is there any methord in powershell..." Powershell is a complete programming language, so there most certainly is. Have you tried anything or did you just come to let other people do your job? Commented Nov 30, 2017 at 7:51

1 Answer 1

2

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'
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.