[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Substitute entires into a powershell script from text file

Posted on 2010-01-08
4
Medium Priority
?
449 Views
Last Modified: 2012-05-08
I've got this code to check the size of a remote folder on our Exchange mailbox server. I've also got a txt file with a list of client names. What I'd like to do is a foreach so that I can substitute the names of the clients into the code  (eventually will have a lot) and output the results. This will give a report of how much space each client is using on the Exchange server.

Obviously my powershell skillz are limited. Any help is appreciated.
$path = "\\mbx01\f$\mdbdata\Client1MBX01"
$colItems = (Get-ChildItem $path -recurse | Measure-Object -property length -sum)
$path +"       " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB" >>c:\log.txt
$path = "\\smbx02\f$\mdbdata\Client2MBX01"
$colItems = (Get-ChildItem $path -recurse | Measure-Object -property length -sum)
$path +"       " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB" >>c:\log.txt

Open in new window

0
Comment
Question by:mrpez1
  • 2
  • 2
4 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 26272427

Would you mind posting an example of the formatting you have in the client file? And an indication of the output you'd like to see?

Naturally you should make up / obscure any sensitive information.

Chris
0
 
LVL 5

Author Comment

by:mrpez1
ID: 26273521
The text file will have client names separated by carriage returns:

e.g.:

CLIENT1
CLIENT2

The client names are uniform in the database paths on the Exchange server:

e.g.:

\\mbx02\f$\mdbdata\CLIENT1MBX01
\\mbx02\f$\mdbdata\CLIENT2MBX01

The output I'd like to see is:

\\mbx02\f$\mdbdata\CLIENT1MBX01       67,727.84 MB
\\mbx02\f$\mdbdata\CLIENT2MBX01       5,238.17 MB

Thanks for the help.

0
 
LVL 5

Accepted Solution

by:
mrpez1 earned 0 total points
ID: 26274582
Think I worked out. Here is the end result. Output is emailed to me via blat.
$LogPath = "e:\scripts\month_end\log.txt"
$Recipient = "me@domain.com"
$tool="blat.exe"
$CmdLine="$LogPath -to $Recipient"
#Check size of mbx db folder
Get-Content e:\scripts\clients.txt | Foreach-Object -process {
$FolderPath = "\\mbx02\f$\mdbdata\" + $_ + "MBX01"
$colItems = (Get-ChildItem $FolderPath -recurse | Measure-Object -property length -sum)
$FolderPath +"       " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB" >>$LogPath
}
#Check Size of Public folder
#Send Email Report
invoke-expression "$tool $cmdLine" | out-null

Open in new window

0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 26275127

Sorry, got a bit busy. All set now?

Chris
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The viewer will learn how to count occurrences of each item in an array.
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 anti-spam), the admin…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

830 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