I have a bunch of files in a folder from a few years back that I want to parse through and list just the years. The catch is I only want to list each year once so I can use that list in another part of my script. What happens is it only lists one year. Here is the code:
$items = get-childitem -Path c:\logfiles\ -recurse
$years = Get-ChildItem -Path $sourcepath\$folder | Select -Property {$_.LastWriteTime.Year} |get-unique
When I look at the variable $years it just lists 2016. I have confirmed that there are files form 2017 and 2018 as well.
To just summarize what I want to list is the following from a list of hundreds of files.
2015
2016
2017
2018
any help would be appreciated as I have never used the get-unique cmdlet before.
Get-Unique not working as expected
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Get-Unique not working as expected
I was looking at it all wrong apparently. Thank you. that should work just fine.