The following code has the benefit of using NT credentials of the
currently logged in user. But, the currently logged in user needs to
have access in Exchange. :)
No passwords in clear text to glean from your scripts.... That's
usually a good thing. :)
$OLECon =
Win32::OLE->GetObject("winmgmts:\\\\$host\\root\\MicrosoftExchangeV2")
||
die "Cannot access WMI on remote machine: ",
Win32::OLE->LastError;
P.S. check out Win32::Exchange (in CPAN or elsewhere) for a lot of
Exchange related CDO and AD manipulations. As well, suggest areas for
improvement, etc. because I haven't done much to it in a while. For
Exchange 5.5, 2000, 2003 and maybe even 2007.. Haven't tested it yet.
:)
Steven
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, May 29, 2007 5:52 PM
To: [email protected]
Subject: Re: Using Win32::OLE to Query Exchange Remotely
Figured it out:
$host = "192.168.42.3";
$user = "vdom\\Administrator";
$pass = "password";
$WMI = Win32::OLE->new('WbemScripting.SWbemLocator') ||
die "Cannot access WMI on local machine: ",
Win32::OLE->LastError;
$OLECon = $WMI->ConnectServer($host, "root\\MicrosoftExchangeV2", $user,
$pass) ||
die "Cannot access WMI on remote machine: ",
Win32::OLE->LastError;
Dax
> I use this to query Exchange Mailbox and Public Folder sizes locally
> on the server:
>
> use Win32::OLE qw(in);
>
> # Get item counts and sizes for each mailbox on the target server # my
> $OLECon=
> Win32::OLE->GetObject('winmgmts:\\\\localhost\\root\\MicrosoftExchange
> V2')
> or die "WMI Connection Failed\n";
>
> my $MailBoxes = $OLECon->ExecQuery("Select * From Exchange_Mailbox")
> or die "WMI Query Failed!\n";
>
> print
>
"-----------------------------------------------------------------------
--------\n";
> print "- Mailbox Size Report
> -\n";
> print
> "---------------------------------------------------------------------
> ----------\n";
> foreach my $mailbox (in $MailBoxes) {
> print "MailboxDisplayName: ......... " .
> $mailbox->MailboxDisplayName . "\n" .
> "\tSize: .......... " . $mailbox->Size . "\n" .
> "\tTotalItems: ......... " . $mailbox->TotalItems . "\n"
.
> "\tStoreName: ......... " . $mailbox->StoreName . "\n";
} print
> "---------------------------------------------------------------------
> ----------\n\n";
>
> my $MailBoxes = $OLECon->ExecQuery("Select * From
> Exchange_PublicFolder") or die "WMI Query Failed!\n";
>
> print
>
"-----------------------------------------------------------------------
--------\n";
> print "- Public Folders Size Report
> -\n";
> print
> "---------------------------------------------------------------------
> ----------\n";
> foreach my $mailbox (in $MailBoxes) {
> print "AddressBookName: ......... " . $mailbox->AddressBookName
. "\n" .
> "\tSize: .......... " . $mailbox->TotalMessageSize .
"\n" .
> "\tTotalItems: ......... " . $mailbox->MessageCount .
"\n" .
> "\tStoreName: ......... " . $mailbox->Path . "\n"; }
>
> How could I do the same thing remotely from a client workstation?
>
> Thanks,
>
> Dax
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs