Hello!
I hope you’re having a fantastic day so far!
I’ve been banging my head on this for a little while and thought I’d try and reach out for some help.
To start, I’d like to put up front, I am hands down a powershell n00b. I am also not extremely versed in general programming (experience 10 years ago haha) - so I’ve been muddling my way through things.
I’m trying to write a script, I’ve got a good chunk of it down, but now I need to write the watcher portion of it.
I pretty much need the watcher to watch for newly created zip folders that are nested within 2 folders. Example of the tree. In this case, I’d be looking for Partybus.#.#.zip:
- Release 1
- Release 1.1
- Partybus.1.1-kdjhfakjfh.zip
- Partywheels.1.1_adflkasdfasd.zip
- Release 1.2
- Partybus.1.2-kdjhfakjfh.zip
- Partywheels.1.2_adflkasdfasd.zip
- Release 1.3
- Partybus.1.3-kdjhfakjfh.zip
- Partywheels.1.3_adflkasdfasd.zip
- Release 2
- Release 2.1
- Partybus.2.1-kdjhfakjfh.zip
- Partywheels.2.1_adflkasdfasd.zip
- Release 2.2
- Partybus.2.2-kdjhfakjfh.zip
- Partywheels.2.2_adflkasdfasd.zip
- Release 2.3
- Partybus.2.3-kdjhfakjfh.zip
- Partywheels.2.3_adflkasdfasd.zip
Now here comes the tricky part. I need to compare the most recent partybus.#.#.zip against the most recent installed partybus version. So if Partybus2.2 is installed and Partybus1.3 is released, nothing will happen; if Partybus 2.3 is released, then proceed to the next steps. I’ve considered having a csv file created and comparing the most recently created partybus zip against it.
I am unsure if the File Watcher will help me in this case, so I built a manual GCI that exports the version into a CSV. My thoughts were the following:
- GCI exports to CSV Watcher1
- Compares against last entry in Watcher2
- If version is higher, add entry in Watcher 2, else nothing.
Here was my stab:
WATCHER 1
Get-ChildItem -path $Stagedrop -include $filter -recurse | Select-Object name | export-csv -path 'c:\temp\watcher1.csv'
Compare against WATCHER2
$file1= import-csv 'c:\temp\Watcher1.csv' $file2= import-csv 'c:\temp\Watcher2.csv' Get-Content 'c:\temp\watcher2.csv' | Select-Object -Last 1 | Compare-Object $file1 InputObject SideIndicator ----------- ------------- "Partybus.2.3-v28e7258c.internal.zip" => @{Name=Partybus.2.3-v28e7258c.internal.zip} <=
That output didn’t make me happy haha, nevermind that I don’t (yet) know how to get the versions to show me greater than if partybus version is greater than 2.3 or smaller than 2.3…
I also tried exporting the last line of Watcher 2 into a Watcher3 CSV and comparing the 2 CSVs. But my Watcher3 ends up looking like this:
Code:
Get-Content 'c:\temp\watcher2.csv' | Select-Object -Last 1 | export-csv -path 'c:\temp\watcher3.csv'
Results:
#TYPE System.String "PSPath","PSParentPath","PSChildName","PSDrive","PSProvider","ReadCount","Length" "C:\temp\watcher2.csv","C:\temp","watcher2.csv","C","Microsoft.PowerShell.Core\FileSystem","7","43"
Which, out of everything, confuses me more… I’m sure I’m just missing one thing.
EITHER WAY! How would you go about this problem? Any suggestions or ideas? Pointing me in the right direction would be an amazing help!
Thank you