Get-ChildItem list txt file and more!

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Get-ChildItem list txt file and more!

Post by apowershelluser »

I want to build a DashBoard GUI for our data migration project from 7 to 10 that I’ll need to analyze different servers (unc paths). It all relies on returning the results of a parent folder, a single txt file nested directly inside the Parent folder and a string inside a Logs folder nested inside the parent

My query begins with the below code to list all the folders on the Server share

Get-childitem \\server\users\*

This would return folders with usernames as you all know

AdamsJ12
BrownR1
DoeJ3
DoeJ4
(there are currently 200 active profiles but this number will increase to thousands before March)

Inside those folders, we create 2 folders (data, logs)and a txt file so a full name of one of the txt file I want is

\\server\users\brownr1\Success.txt

So the parent is brownr1

The GUI displays:
Textboxes to show count of migrations that are, currently in a wait state (success), a failed state, or a synching State

A DGV to display
The username and folder(s) it failed (this could be multiple folders if for example the user is working on a file from their desktop and documents, or they are encrypted), lastwritetime, createdtime

Be able to click on a DGV row and open to (Invoke-Item) the selected user folder for further inspection if needed

Being able to see these will help me track down issues and fix for the next release of the application and will also show the grand scheme to the bosses

I know it’s a lot, but it’s simple at the same time :)
Parent Folder
Txt File
String from a txt file nested in a Logs folder

I should be able to figure out the GUI if I can pull these three items
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-ChildItem list txt file and more!

Post by jvierra »

This is a good learning project for both PowerShell and PowerShell Studio.

Start by designing you form. Add the code required to the form events.

To learn how to use PowerShell with forms start with the Sapien InfoCenter here: https://info.sapien.com/index.php/guis
There are numerous videos on YouTube for PSS use.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Get-ChildItem list txt file and more!

Post by apowershelluser »

Thanks for replying. I think I can do the GUI, it’s just returning those three items. I can pull them individually and if needed, that’s what I’d do but query the server three different times isn’t what I’m looking to do.

Any help with an example of returning the parent folder and a sub txt file would get this project going
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-ChildItem list txt file and more!

Post by jvierra »

So you are not asking about a form but how to query a folder on a server for a file in multiple locations.

Just use a wild card.

Get-ChildItem \\server\users\*\Success.txt -recurse
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Get-ChildItem list txt file and more!

Post by apowershelluser »

Hello,

So I was absolutely overthinking this when I realized that I was going about this the wrong way.

To get what I need, successes, failures, synching where all within an easy query. There is a file that is named failed, synching, success. Duh!

Now I just query the server with get-childitem \\server\users to fill a grid, then use | where-object on the files to fill in textboxes with total counts of the project the bosses need to know.

Then use a radiobutton and regular button to list those specific folders in the grid - see 2nd to last paragraph for my question...

I found the template for Job Grid ( or whatever it’s called ) which is perfect all but one item. My grid current is just the folder name so

\\server\users\user1
\\server\users\user2
etc...

What I’d like to do is click on the row and invoke-item and open Windows Explorer to the selected text which is the directory. I’ve read about how to click on a row and something happens but no examples of opening a directory.

Work-On:
2nd column is to read a file inside the \Logs directory and list the reason it failed. There’s multiple reasons in different files so that will be a pain but it’s not needed for the project currently.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-ChildItem list txt file and more!

Post by jvierra »

I am sorry but I cannot make any sense out of what you are trying to ask.


Please be aware that technical forums are for answering specific technical questions. Designing solutions or teaching you PowerSHell or Windows Forms is beyond the scope of any technical forum.

Can you just as one question and show the code you have used that presents the problem or cause an error.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Get-ChildItem list txt file and more!

Post by apowershelluser »

There’s no error. I just don’t know what to write inside the click event. I’ve researched this topic for the last few days to no avail, hence why I’m asking here.

What I’d like to do is double click a row of the datagridview and it opens to a Windows Explorer window. The row text is just the name and location of the server.

So if a row is
\\server\users\john

I click on it and a Windows Explorer dialog opens to that directory.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-ChildItem list txt file and more!

Post by jvierra »

What have you tried? Post your code.

To run explorer with a specific folder just add the folder to the command line.
explorer d:\test
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Get-ChildItem list txt file and more!

Post by apowershelluser »

I’m mobile but I’m thinking this might get me where I want to go

$datagridview1_SelectionChanged={
$r=$datagridview1.SelectedRows[0].Cells[0].Value
[void][System.Windows.Forms.MessageBox]::Show($r,"test")
}

I’ll post back in a few days
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Get-ChildItem list txt file and more!

Post by apowershelluser »

jvierra wrote: Fri Nov 24, 2017 5:37 pm What have you tried? Post your code.

To run explorer with a specific folder just add the folder to the command line.
explorer d:\test
$datagridview1_Click={
#TODO: Place custom script here
Invoke-Item $datagridview1.SelectedCells[0].FormattedValue
}

This was what I meant to post. Now more digging for other items :D as I can mark this one off the list
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked