?
Solved

Seach for folder on multiple computers powershell.

Posted on 2013-02-07
2
Medium Priority
?
209 Views
Last Modified: 2013-02-07
I have the following powershell...

Get-ChildItem -path "C:\Test\Hub" -filter "initiated.txt" -recurse | Select-Object CreationTime, LastWriteTime, @{Name="Result";Expression={($_.Directory -Replace ([regex]::Escape("C:\Test\Hub"),""))}}, @{Name="RunTime";Expression={"{0:N0}" -f ($_.LastWriteTime - $_.CreationTime).TotalSeconds}}| Where-Object {$_.RunTime -gt 0}  | Sort-Object "CreationTime"

Open in new window


And need to do three things, I would ideally like to do this in the one statement as I want to pipe the output of the command to a graph generator cmdlet - but I will take what I can get!...

1) For each 'Result' value found (will be a folder name) I want to search 4 remote machine paths ('MAC1','MAC2','MAC3','MAC4') to see if the folder exists on these machines - it will exist on one of them and return the appropriate machine name to the piped output of the cmdlet.

2) The 'RunTime' is being output I guess as a formatted number i.e. 20,000. I would like to have this as a straight integer with no comma delimeter. I have tried...

@{Name="RunTime";Expression={"{0:N0}" -f [integer]::($_.LastWriteTime - $_.CreationTime).TotalSeconds}}

Open in new window


to no avail.

3) At the moment the code searches for 'initiated.txt' files, but I can see the requirements changing to include files of type '*.alo'. Is there a way I can add this as a search option in the statement and populate a new column with something like ALO/TXT to differentiate? This is the least important option at the moment.

Any help greatly appreciated.
0
Comment
Question by:Blowfelt82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 38863305
cls
'MAC1','MAC2','MAC3','MAC4' | %{
$path = "\\$_\C$\Test\Hub"
Get-ChildItem $path -include ('initiated.alo', 'initiated.txt') -recurse | Select-Object CreationTime, LastWriteTime, @{Name="Result";Expression={($_.Directory -Replace ([regex]::Escape("$path"),""))}}, @{Name="ALO/TEXT";Expression={$_.Extension}},@{Name="RunTime";Expression={"{0}" -f ($_.LastWriteTime - $_.CreationTime).TotalSeconds}}| Where-Object {$_.RunTime -gt 0}  | Sort-Object CreationTime 
}

Open in new window

0
 

Author Comment

by:Blowfelt82
ID: 38863518
Thats a great idea searching from the remote directories as a starting point! Great Answer
0

Featured Post

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question