E
E
Evgeny Kotov2020-10-07 13:18:44
PowerShell
Evgeny Kotov, 2020-10-07 13:18:44

What is the correct way to set a variable to the size of the largest file in a directory?

Help me figure out the correct spelling of the syntax
I'm trying like this, but the variable is empty

Set-Location C:\Users\
$status = get-childitem -Recurse | Sort-Object -Descending -Property length | Select -First 1 length

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2020-10-07
@eskotov

well, it’s hardly empty, if only the directory is empty,
most likely there is an object with one property - Length
if you need only a number, then like this

get-childitem -Recurse | Sort-Object -Descending -Property length | Select -First 1 -ExpandProperty Length

will be either empty or a number

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question