#Use Get-Item/Child-Item Length Property Exactly As Displayed?

1 messages · Page 1 of 1 (latest)

buoyant gazelle
#

Hello all, somewhat stuck and I hope you can help.
I want to be able to check if the Length property of items contains either "(" or ")", checked with either Get-ChildItem or Get-Item.
For example, in the below the "()" are there.

Get-Item "Y:\Apps\sslscan-win-2.0.10\sslscan.exe"
Directory: Y:\Apps\sslscan-win-2.0.10

Mode                LastWriteTime         Length Name                                                                                                                                                                                
----                -------------         ------ ----                                                                                                                                                                                
-a----       27/04/2021     16:39      (3440142) sslscan.exe

When i specifically check the Length it drops them. Is it possible to keep them?

(Get-Item "Y:\Apps\sslscan-win-2.0.10\sslscan.exe").Length
3440142
modern void
#

No, you'll have to add them back.

'({0})' -f (Get-Item "Y:\Apps\sslscan-win-2.0.10\sslscan.exe").Length
worldly hound
#

Length is an integer, if that's what you're asking
if you want to have a custom format, you can change the definition so it draws parenthesis
Usually the @() operator makes escapes simpler

buoyant gazelle
#

Thank you but unfortunately that won't work for me, some files intentionally don't have them, and i need to differentiate between them

Get-ChildItem "Y:\Apps\sslscan-win-2.0.10"
Directory: Y:\Apps\sslscan-win-2.0.10

Mode                LastWriteTime         Length Name                                                                                                                                                                                
----                -------------         ------ ----                                                                                                                                                                                
-a----       25/03/2021     16:17           7065 README.md                                                                                                                                                                   
-a----       27/04/2021     16:39      (3440142) sslscan.exe                                                                                                                                                                      
-a----       27/04/2021     16:39          (310) sslscan.sig

The ones that do have them are files that have been archived away so aren't actually taking up any space

worldly hound
#

Maybe I'm misreading the question. You're trying to make it look like the last screenshot?`

buoyant gazelle
#

Sorry, i'm probably extremely clear.
I'm trying to check if the length of each of those objects contains a "(" or ")", if it does i want to disregard the result, if it doesn't i want to keep that result.
But the issue is when i | Select Length the brackets are gone and i'm only left with the number. So if i try to do a If (blah.length -contains "(") it will always return negative because the brackets are dropped

worldly hound
#

I think you're asking the wrong property, because length is an integer

Even though the table format has () in it
You can modify the behavior, like showing 5mb even though the length value is an integeter

Formatdata: changing the format, without changing datatypes:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/update-formatdata?view=powershell-7.3
typedata: and changing typedata
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/update-typedata?view=powershell-7.3

modern void
#

Are you trying to get a list of files that have been archived? If so, does the Attributes property show that? I don't have any files that are archived, just ones that are marked as ready to be archived.

(Get-ItemProperty "Y:\Apps\sslscan-win-2.0.10").Attributes
worldly hound
#

But the issue is when i | Select Length the brackets are gone and i'm only left with the number. So if i try to do a
Okay so maybe your question is how to filter the results, and you were going for parethesis to filter them?
If yes, then you probably don't need to do anything with typedata or formatdata
but filter on attributes like Colby

buoyant gazelle
#

Yup, thank you both! Using the Get-ItemProperty command seems to get me exactly what i need. Thank you so much

modern void
#

I'm curious, what does it show for files that have been archived? On a file that is marked as "ready to be archived", it shows "Archive" for me. The file does not have () around its Length.

buoyant gazelle
#

We actually have a system/software in place that "archives" files over a certain age. It replaces them with pointer files which still show the original files size but isn't actually there.
It's not the conventional windows archiving flag, because every file has "Archive" ticked against it in properties/attributes, but only some are "archived" away per se.

So for a file that's actually there, the length property using Get-Item shows as just a number and the attribute using Get-ItemProperty shows as "Archive, Sparse"
For a file that isn't there the length property using Get-Item shows a number in parenthesis and the attribute using Get-ItemProperty shows "Archive, Sparse, Offline"

So using the Get-ItemProperty i'm able to check if it has the "Offline" attribute, not sure if it would work the same with a normal system that doesn't have our type of archiving. The only similiar thing i could think of is OneDrive with how you can have files in the cloud only but they still show up on your PC

worldly hound
#

I forget the relationship between reparse points and symbolic links
They seem to say all symbolic links are a reparse point, so they filtered like this
I included -Force otherwise not all files are returned.

gci $Env:USERPROFILE -Force | ?{ $_.Attributes -match 'ReparsePoint' }
gci $Env:USERPROFILE -Force | ? -not { $_.Attributes -match 'ReparsePoint' }
#

Attributes is a true [flags] attribute, where they actually use bitwise operators
using a regex seems to work