I’ve been playing around a bit more this week with the MSH beta and decided I’d share some of the stuff you can do using the WMI functionality in Monad. To start off here’s some one-liners that can be used to get information from the Exchange 2003 WMI classes. Learning how to do things in monad is a little tricky at the moment other peoples blog’s tend to be the best source of information I worked out the one-liners using a post from Adam Barr’s blog
http://www.proudlyserving.com/archives
/2005/08/monad_and_wmi.html also the following blog was really useful as well as it has a whole bunch of samples that helped when I got stuck. http://mow001.blogspot.com/
Display the SMTP Message Queues
get-wmiobject -class Exchange_SMTPQueue -Namespace ROOT\MicrosoftExchangev2 -ComputerName servername | select-object LinkName,MessageCount,Size
Display Mailbox sizes
get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName servername | select-object MailboxDisplayName,TotalItems,Size
Display Users that are logged onto OWA
get-wmiobject -class Exchange_Logon -Namespace ROOT\MicrosoftExchangev2 -ComputerName servername -filter "ClientVersion = 'HTTP' and LoggedOnUserAccount != 'NT AUTHORITY\\SYSTEM'" | select-object LoggedOnUserAccount,MailboxDisplayname
Display all public folder sizes and message counts
get-wmiobject -class Exchange_Publicfolder -Namespace ROOT\MicrosoftExchangev2 -ComputerName servername | select-object name,messagecount,totalmessagesize
The last one is a sample of listening to the Exchange_Logon class modification events this one still needs a little bit of tweaking
$objConn = New-Object System.Management.ConnectionOptions
$objconn.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
$objconn.EnablePrivileges = 1
$tspan = New-Object System.TimeSpan(0, 0, 10)
$exmangescope = New-Object System.Management.ManagementScope("\\servername\root\MicrosoftExchangeV2", $objconn);
$query = New-Object System.Management.WqlEventQuery("__InstanceModificationEvent",$tspan, "TargetInstance isa `"Exchange_Logon`" and TargetInstance.ClientVersion = `"HTTP`" and TargetInstance.LoggedOnUserAccount != `"NT AUTHORITY\\SYSTEM`"")
$watcher = New-Object System.Management.ManagementEventWatcher($exmangescope,$query)
$e = $watcher.WaitForNextEvent()
$des = 1
while($des -eq 1){
$e.TargetInstance.LoggedOnUserAccount
$e = $watcher.WaitForNextEvent()
Trap{Break}
}
Thursday, November 24, 2005
Subscribe to:
Post Comments (Atom)
7 comments:
glad my blog did help ;-),
For watching the event in the last script, you could use a hidden form to catch the events without blocking the interface.
I do the same here with a filewatcher.
http://mow001.blogspot.com/2005/10/msh-directory-watcher-with-popup.html
hope this helps tweaking your last script.
gr /\/\o\/\/
Cool thats a good idea i'll give it a try out.
Cheers
Glen
Hey Glen,
Any idea's on how I might be able to use this WMI script to display a users MBX size using ASP? I want to give a small Web tool to my helpdesk guys so they can quickly look up a users mailbox size.
Tony.
As long as your running Exchange 2003 using WMI in a asp page (or asp.net would be better) have a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/creating_active_server_pages_for_wmi.asp
The only real issue is security you need to make sure the code is running under a user context that has access to the Exchangev2 WMI namespace. With ASP.NET you could use impersonation to do this. You need to make sure that user you using has a least the rights talked about in this article http://www.microsoft.com/technet/prodtechnol/exchange/guides/E2k3ADPerm/29fa71f4-60bc-4fea-98eb-86528a9106d9.mspx
To display the sizes of all Mailboxes using Monad for Exchange 2003
get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName servername | select-object MailboxDisplayName,TotalItems,Size
Wow, all this ridiculous scripting could be eliminated by having a simple GUI. Didn't they go from DOS to windows for that reason? Why are they going back from windows to DOS again? I'm confused.
Perhaps so, but you can't script a GUI for automation and information gathering purposes, system maintenance etc.
Post a Comment