What does this powershell script do?

127 Views Asked by At

currently I watch the course about IT support and encountered this script:

$FILE = $GET_HTML.Links | Select-Object @{Label='href';
Expression={@{$true=$_.href}[$_.href.EndsWith('win64.exe')]}} |
Select-Object -ExpandProperty href

I figured out that we somehow use hashtables to filter out the desired link but I want to know how it works in detail. Would appreciate your help.

1

There are 1 best solutions below

0
js2010 On

@{$true=$_.href} is a hashtable, and [$_.href.EndsWith('win64.exe')] picks the hashtable element that has a true or false key, but there is no false key entry.

@{$true = 'foowin64.exe'}

Name                           Value
----                           -----
True                           foowin64.exe


@{$true = 'foowin64.exe'}[$true]

foowin64.exe


@{$true = 'foowin64.exe'}[$false] -eq $null

True