\root \ MicrosoftExchangeV2 ..WMI在Exchange 2007中不起作用 [英] \root\MicrosoftExchangeV2 ..WMI is not working in Exchange 2007
问题描述
您好我们公司刚刚从Exchange 2003迁移到2007.我们每周都使用大量的vb脚本来获取邮箱详细信息,现在它已不再使用Exchange 2007了。 (WMI名称空间不能用于ex2007)有人可以帮助转换为PowerShell或建议其他方式获取相同的信息吗?
旧脚本如下: -
"================================================= ============
'目的:显示为Exchange服务器找到的每个Exchange_Mailbox,并显示Exchange_Mailbox上的所有属性
'对象
'更改:cComputerName [string]要访问的计算机
'输出:显示每个Exchange_Mailbox的名称和属性
'==================== ===========================================
Hi
Our company is just migrated from exchange 2003 to 2007.We were using lot of vb script every week to fetch mailbox details, now it is no longer working with exchange 2007.( WMI namespace will not work against ex2007) Could someone help to convert to powershell or suggest some other way to fetch the same information?
old script has given below:-
'=============================================================
' Purpose: Display each Exchange_Mailbox found for Exchange server,
' and show all properties on the Exchange_Mailbox
' objects
' Change: cComputerName [string] the computer to access
' Output: Displays the name of each Exchange_Mailbox and properties
'===============================================================
Dim cComputerName
Dim arrComputers
Dim i
Const Const cWMINameSpace =" root / MicrosoftExchangeV2"
Const cW MIInstance =" Exchange_Mailbox"
Dim cComputerName
Dim arrComputers
Dim i
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Dim strWinMgmts'WMI的连接字符串
Dim objWMIExchange'Exchange命名空间WMI对象
Dim listExchange_Mailboxs'ExchangeLogons collection
Dim objExchange_Mailbox '单个ExchangeLogon WMI对象
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxs ' ExchangeLogons collection
Dim objExchange_Mailbox ' A single ExchangeLogon WMI object
设置objConnection = CreateObject(" ADODB.Connection")
objConnection.Open" Provider = ADsDSOObject;"
设置objCommand = CreateObject(" ADODB.Command")
objCommand.ActiveConnection = objConnection
'Starter WMI
arrComputers = Array(" st-excl21")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'Starter WMI
arrComputers = Array("st-excl21")
'Legge inn datofornårjobbenerkjørt
Wscript.Echo" Date:" &安培;现在
' Legge inn dato for når jobben er kjørt
Wscript.Echo "Date: " & Now
对于i = 0到UBound(arrComputers)
For i = 0 to UBound(arrComputers)
'分配计算机名称
cComputerName = arrComputers(i)
'写报告标题
Wscript.Echo'服务器名称:" &安培; cComputerName
'Assign computer name
cComputerName = arrComputers(i)
'Write report header
Wscript.Echo "Server Name: " & cComputerName
'连接到计算机
'strWinMgmts =" winmgmts:{impersonationLevel = impersonate}!//" &安培; cComputerName& " /" &安培; cWMINameSpace
'设置objWMIExchange = GetObject(strWinMgmts)
On On Error Resume Next
设置objWMIExchange = GetObject(" winmgmts:\\"& cComputerName&" \ root \ MicrosoftExchangeV2")
'Connect to computer
'strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & cComputerName & "/" & cWMINameSpace
'Set objWMIExchange = GetObject(strWinMgmts)
On Error Resume Next
Set objWMIExchange = GetObject("winmgmts:\\" & cComputerName & "\root\MicrosoftExchangeV2")
'确认我们能够正确设置对象。
如果Err.Number<> 0然后
Wscript.Echo Err.Description
WScript.Echo"错误:无法连接到WMI命名空间。"
On On Error Goto 0
否则
On Error Goto 0
'当前存在的资源显示为Exchange命名空间中的Exchange_Mailbox实例列表。
设置listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
'是否返回了任何Exchange_Mailbox实例?
wscript.echo listExchange_Mailboxs.count
如果(listExchange_Mailboxs.count> 0)那么左''写列标题
Wscript.Echo" EmployeeID; Size; ServerName; SAMAccount; Department ; MailboxDisplayName; TotalItems; StoreName; LastLoggedOnUserAccount; LastLogoffTime; LastLogonTime"
'遍历Exchange_Mailbox对象列表。
对于listExchange_Mailboxs中的每个objExchange_Mailbox
'sAMAccount
strUserName = right(objExchange_Mailbox.LegacyDN,len(objExchange_Mailbox.LegacyDN) - instrRev(objExchange_Mailbox.LegacyDN," ="))
'部门
'Verify we were able to correctly set the object.
If Err.Number <> 0 Then
Wscript.Echo Err.Description
WScript.Echo "ERROR: Unable to connect to the WMI namespace."
On Error Goto 0
Else
On Error Goto 0
'The Resources that currently exist appear as a list of Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
'Were any Exchange_Mailbox Instances returned?
wscript.echo listExchange_Mailboxs.count
If (listExchange_Mailboxs.count > 0) Then
'Write column headers
Wscript.Echo "EmployeeID;Size;ServerName;SAMAccount;Department;MailboxDisplayName;TotalItems;StoreName;LastLoggedOnUserAccount;LastLogoffTime;LastLogonTime"
'Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxs
'sAMAccount
strUserName = right(objExchange_Mailbox.LegacyDN,len(objExchange_Mailbox.LegacyDN) - instrRev(objExchange_Mailbox.LegacyDN,"="))
'Department
objCommand.CommandText ="< LDAP:// dc = statoil,dc = net> ;;(&(objectCategory = User )" &安培; "(samAccountName ="& strUserName&")); department,employeeid; subtree"
set objRecordSet = objCommand.Execute
objCommand.CommandText = "<LDAP://dc=statoil,dc=net>;(&(objectCategory=User)" & "(samAccountName=" & strUserName & "));department,employeeid;subtree"
Set objRecordSet = objCommand.Execute
if objRecordset.RecordCount = 0然后
department =" null"
employeeid =" null"
否则
department = objRecordSet(" department")
employeeid = objRecordSet(" employeeid" ;)结束如果
如果isNull(employeeID)则
employeeID =" CommonMailbox"
department =" *"
结束如果
If objRecordset.RecordCount = 0 Then
department="null"
employeeid="null"
Else
department=objRecordSet("department")
employeeid=objRecordSet("employeeid")
End If
If isNull(employeeID) then
employeeID="CommonMailbox"
department="*"
End If
如果是isNull(部门)那么
department =" *"
结束如果
If isNull(department) then
department="*"
End If
LastLoggedOnUser = objExchange_Mailbox.LastLoggedOnUserAccount
如果是isNull(LastLoggedOnUser)则是lt LastLoggedOnUser =" *"
结束如果
LastLoggedOnUser=objExchange_Mailbox.LastLoggedOnUserAccount
If isNull(LastLoggedOnUser) then
LastLoggedOnUser="*"
End If
LastLogOff = objExchange_Mailbox.LastLogoffTime
如果isNull(LastLogOff)则为lastLogOff =" *"
结束如果
LastLogOff=objExchange_Mailbox.LastLogoffTime
If isNull(LastLogOff) then
LastLogOff="*"
End If
LastLogon = objExchange_ Mailbox.LastLogonTime
如果是isNull(LastLogon)那么
LastLogon =" *"
结束如果
LastLogon=objExchange_Mailbox.LastLogonTime
If isNull(LastLogon) then
LastLogon="*"
End If
'写入属性
Wscript.Echo employeeID&英寸;" &安培; _
objExchange_Mailbox.Size&英寸;" &安培; _
objExchange_Mailbox.ServerName&英寸;" &安培; _
strUserName&英寸;" &安培; _
部门&英寸;" &安培; _
objExchange_Mailbox.MailboxDisplayName&英寸;" &安培; _
objExchange_Mailbox.TotalItems&英寸;" &安培; _
objExchange_Mailbox.StoreName&英寸;" &安培; _
LastLoggedOnUser&英寸;" &安培; _
LastLogOff&英寸;" &安培; _
上次登录
下一个
其他
如果没有返回任何Exchange_Mailbox实例,则显示该内容。
WScript.Echo"警告:未返回任何Exchange_Mailbox实例。"
结束如果结束如果
清除
设置objWMIExchange =无设置listExchange_Mailboxs =无设置objExchange_Mailbox = Nothing
< br'''写报告页脚
Wscript.Echo" ********************************** **************" ;
'Write properties
Wscript.Echo employeeID & ";" & _
objExchange_Mailbox.Size & ";" & _
objExchange_Mailbox.ServerName & ";" & _
strUserName & ";" & _
department & ";" & _
objExchange_Mailbox.MailboxDisplayName & ";" & _
objExchange_Mailbox.TotalItems & ";" & _
objExchange_Mailbox.StoreName & ";" & _
LastLoggedOnUser & ";" & _
LastLogOff & ";" & _
LastLogon
Next
Else
'If no Exchange_Mailbox instances were returned display that.
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
End If
End If
'Cleanup
Set objWMIExchange = Nothing
Set listExchange_Mailboxs = Nothing
Set objExchange_Mailbox = Nothing
'Write report footer
Wscript.Echo "***********************************************************************************"
下一个
清理
设置oRs =无结果'oCon.Close
设置oCon =什么都没有设置oCommand =什么都没有设置oRoot =什么都没有设置oDomain = Nothing
objConnection.Close
问候郎SAK
Next
'Cleanup
Set oRs = Nothing
'oCon.Close
Set oCon = Nothing
Set oCommand = Nothing
Set oRoot = Nothing
Set oDomain = Nothing
objConnection.Close
Regards
SAK
推荐答案
Exchange Exchange 2000/2003中的WMI类在Exchange 2007或更高版本上不再可用,您现在需要使用Exchange命令行管理程序cmdlet,例如,等效的是get-mailboxstatistics,请参阅 http://technet.microsoft.com/en-us/library/bb124612.aspx 和获取邮箱,具体取决于您感兴趣的属性,可能需要组合多个cmdlet有一个很好的帖子来做这个 http://exchangeexchange.com/blogs/joel.stidley/archive/2008/02/22/quick-powershell-tip-using-get-mailboxstatistics.aspx ,它们看起来像是您发布的脚本的大部分内容是在做。对于某些属性,ADSI在Powershell中仍然有用,并且在VBS中更容易使用。
干杯格伦
The Exchange WMI classes from Exchange 2000/2003 are no longer available on Exchange 2007 or above you now need to use the Exchange Management Shell cmdlets eg the equivalent is get-mailboxstatistics see http://technet.microsoft.com/en-us/library/bb124612.aspx and Get-mailbox depending on the properties your interested in you may need to combine multiple cmdlets there a good post on doing this http://exchangeexchange.com/blogs/joel.stidley/archive/2008/02/22/quick-powershell-tip-using-get-mailboxstatistics.aspx which look like cover most of what the script you posted is doing. ADSI is also still useful in Powershell for some properties and a lot easier to use then in VBS.
Cheers
Glen
这篇关于\root \ MicrosoftExchangeV2 ..WMI在Exchange 2007中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!