[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Need to create Powershell cmdlet

I ran the following command in Exchange powershell on Windows 2008 against Exhcange 2007. The commands work perfectly when run one at a time. I need detailed instructions on creating and run a Cmdlet that generates a text file for each mailbox as if I reran each of these commands in powershell.

Get-MailboxFolderStatistics -Identity ca >c:\mailstat-ca.txt
Get-MailboxFolderStatistics -Identity bf >c:\mailstat-cb.txt
Get-MailboxFolderStatistics -Identity cc >c:\mailstat-cc.txt
Get-MailboxFolderStatistics -Identity cd >c:\mailstat-cd.txt
Get-MailboxFolderStatistics -Identity ce >c:\mailstat-ce.txt
Get-MailboxFolderStatistics -Identity cf >c:\mailstat-cf.txt
Get-MailboxFolderStatistics -Identity cg >c:\mailstat-cg.txt
Get-MailboxFolderStatistics -Identity ch >c:\mailstat-ch.txt
0
Tony Giangreco
Asked:
Tony Giangreco
  • 2
  • 2
2 Solutions
 
Dale HarrisCommented:
Just take this entire text you've written and put it into a notepad and save it as a .ps1.  Then call that script from the Powershell console.  If you want to create a function for it, you could do this:

Function Get-AllMailboxStatistics {
Get-MailboxFolderStatistics -Identity ca >c:\mailstat-ca.txt
Get-MailboxFolderStatistics -Identity bf >c:\mailstat-cb.txt
Get-MailboxFolderStatistics -Identity cc >c:\mailstat-cc.txt
Get-MailboxFolderStatistics -Identity cd >c:\mailstat-cd.txt
Get-MailboxFolderStatistics -Identity ce >c:\mailstat-ce.txt
Get-MailboxFolderStatistics -Identity cf >c:\mailstat-cf.txt
Get-MailboxFolderStatistics -Identity cg >c:\mailstat-cg.txt
Get-MailboxFolderStatistics -Identity ch >c:\mailstat-ch.txt
}

Then just call it from the powershell window by doing this:

Get-AllMailboxStatistics


This will do exactly what you've written in the function.

HTH,

Dale Harris
0
 
Tony GiangrecoAuthor Commented:
What folder do I save it into so powershell finds it?
0
 
KenMcFCommented:
There are several ways you can do this. But I think you may be having issues because the snapin is not loaded. If you do what Dale suggested and run from within the Exchange console it will work to.

So try this

Save this as a .PS1 file

Get-AllMailboxStatistics.PS1
Get-MailboxFolderStatistics -Identity ca >c:\mailstat-ca.txt
add-pssnapin *EX*
Get-MailboxFolderStatistics -Identity bf >c:\mailstat-cb.txt
Get-MailboxFolderStatistics -Identity cc >c:\mailstat-cc.txt
Get-MailboxFolderStatistics -Identity cd >c:\mailstat-cd.txt
Get-MailboxFolderStatistics -Identity ce >c:\mailstat-ce.txt
Get-MailboxFolderStatistics -Identity cf >c:\mailstat-cf.txt
Get-MailboxFolderStatistics -Identity cg >c:\mailstat-cg.txt
Get-MailboxFolderStatistics -Identity ch >c:\mailstat-ch.txt

Open in new window

0
 
Dale HarrisCommented:
I would recommend making a folder called "Scripts" in your C:\ drive.  Then make sure you're in the C:\Scripts folder by typing in

cd c:\scripts
before you run your script.

Either that, or you can just run it from the console by the long name:

C:\Scripts\Get-AllMailboxStatistics.ps1

This will allow you to call it from the console wherever it starts you out.

Also, remember to type in:

Set-ExecutionPolicy Unrestricted

If you want to enable running scripts that you make.

HTH,

Dale Harris
0
 
Tony GiangrecoAuthor Commented:
In the PW Script, how do I add a short date & time variable (yy-mm-dd-hh-mm to each users output report file name so the historical reports don't get over written?

I ran the reports mentioned above and they worked great, but how do I limit it to report only the following information per mailbox:
1. Mailbox size
2. Deleted Items folder size
3. Inbox folder Size
4. Sent Items folder size  
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now