我正在尝试使用以下代码获取用户的最后登录日期。我的问题是将 powershell 结果从 powershell 变量 $MailboxData 获取到 VB.net 变量中。
该displayname = obj.Members("alias").Value.ToString
行只返回一个错误。
有谁有想法吗 ?
Dim scripttext As String
scripttext = "$MailboxData = @() " & vbCrLf & _
"$mailboxes = Get-Mailbox -ResultSize unlimited " & vbCrLf & _
"foreach ($mailbox in $mailboxes) { " & _
"$DBObject = new-object PSObject " & _
"$DBObject | add-member NoteProperty -Name Alias $Mailbox.alias " & _
"$DBObject | add-member NoteProperty -Name LastLogonTime (Get-MailboxStatistics $mailbox.alias).LastLogonTime " & vbCrLf & _
"$MailboxData = $MailboxData + $DBObject " & _
"}" & vbCrLf & _
"$mailboxData " & vbCrLf
powershell.Commands.AddScript(scripttext)
powershell.Runspace = myRunSpace
results = powershell.Invoke()
Dim displayname As String
Dim lastLogon As String
For Each obj As PSObject In results
Try
displayname = obj.Members("alias").Value.ToString
Catch ex As Exception
displayname = Nothing
End Try
Try
lastLogon = Convert.ToDateTime(obj.Members("LastLogonTime").Value.ToString)
Catch exc As Exception
lastLogon = Nothing
End Try
Next