0

I want to get the contents of a file.

The format of file is like this

Disk0MapForUefiBootOrder
    PciRoot(0x0)/Pci(0x14,0x0)

    PciRoot(0x0)/Pci(0x1B,0x0)/Pci(0x0,0x0)/NVMe(0x1,7D-F0-B6-71-B7-38-25-00)

    PciRoot(0x0)/Pci(0x1B,0x4)/Pci(0x0,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)

    PciRoot(0x0)/Pci(0x17,0x0)/Sata(0x1,0xFFFF,0x0)

    BBS(0xFFFF,,0x0)/PciRoot(0x0)/Pci(0x14,0x0)

Fast Charge
    Disable
    *Enable 

......

I want to read the value of this Disk0MapForUefiBootOrder which contains NVMe and Sata, which are:

PciRoot(0x0)/Pci(0x1B,0x0)/Pci(0x0,0x0)/NVMe(0x1,7D-F0-B6-71-B7-38-25-00)

PciRoot(0x0)/Pci(0x1B,0x4)/Pci(0x0,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)

PciRoot(0x0)/Pci(0x17,0x0)/Sata(0x1,0xFFFF,0x0)

and pass it to the output file. Then I have to sort it with a rank.

I tried this, but I can only read the content. But I can not rank it.

Can anyone help me please?

$FileContents = Get-Content "D:\Boot\file.txt" | Select-String -Pattern "PciRoot" | Out-File D:\Boot\Out2 -Force
    $FileContents
    $Rank = @{
        'NVMe' = 1
        'Sata' = 2
    }
    $FileContents |
        Where-Object { $Rank.Contains("NVMe" -and "Sata") } | Sort-Object {[int64]$_.Size} |
        Sort-Object { $Rank["NVMe" -and "Sata"] }|
        Export-Csv 'Output.csv' -NoType

2 Answers 2

1

You can do the following if we assume that the data you want is indented:

$found = $false
switch -regex -file file.txt {
    'Disk0MapForUefiBootOrder' { $found = $true; continue }
    'nvme|sata' { if ($found) { $_.Trim() }}
    '^\S' { if ($found) { return }}
}
Sign up to request clarification or add additional context in comments.

4 Comments

I still have a problem how to sort it, I want to create a rank of those data, If the nvme rank 1, it will return true, and false if sata rank 1. Could you please help me, Thank you buddy
Can you explain how you want to sort? It doesn't seem clear because your code is sorting by Size and the size property is not present in the file exerpt.
The output is an array. So if the array[0] is contain of 'sata', it will return false
I have to output the return first to a file, then read the output file
0

You could use Select-String with -Pattern.

$FileContents= Get-Content $FilePath | Select-String -Pattern "NVMe|Sata"

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.