1
我試圖獲取使用以下代碼的用戶的上次登錄日期。我的問題是從powershell變量$ MailboxData的PowerShell變成VB.net變量。將Powershell變量導入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
我知道了,謝謝基思的結束,即正常工作。 – Dougs