Problem with script to check on wich CAS Array server a user is logged on.

Hi Everyone,

maybe you can help me out here.

I have build a scipt for our servicedesk so they can check easily to wich CAS server an user is connected.
The exchange enviroment is an CAS Array with Networkload balancer in place.
No Exchange management console is installed or is possible.
So the idea is; A users calls with the complaint exchange is slow, outlook hangs etc. 
The servicedesk runs te script, which connects to exchange, and shows on wich of the CAS servers the user has landed.
When i run the scipt locally on the Exchange Server the script works just fine.
But running it from another server it fails with error: Cannot bind argument to parameter 'Identity' because it is null.

Here is the code, would be great if someone can help us out here..

$UserCredential = Get-Credential
$Session = New-PSSession ConfigurationName Microsoft.Exchange ConnectionUri http://EXCHANGESERVERNAME/PowerShell/'?serializationlevel=Full' -Authentication Kerberos Credential $UserCredential 
Import-PSSession $Session
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200) 
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
    {$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
    {$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20) 
$objLabel.Size = New-Object System.Drawing.Size(280,20) 
$objLabel.Text = "Please enter the information in the space below:"
$objForm.Controls.Add($objLabel) 

$objTextBox = New-Object System.Windows.Forms.TextBox 
$objTextBox.Location = New-Object System.Drawing.Size(10,40) 
$objTextBox.Size = New-Object System.Drawing.Size(260,20) 
$objForm.Controls.Add($objTextBox) 

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$User
Get-LogonStatistics -Identity $User |Sort-Object LastAccessTime -Descending  |?{$_.ApplicationId -Like "Client=MSExchangeRPC*"}|Select ClientName,ClientVersion,Latency,ApplicationId,LastAccessTime,CurrentOpenFolders |ft
pause

February 18th, 2015 6:10pm

I see two problems. The first is that Get-LogonStatistics is deprecated as of Exchange 2013. You didn't mention what version of Exchange you have but this solution may not be valid in the future: http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2013/monitoring/get-logonstatistics-exchange-2013.html

The other issue is that you never actually set the value of $User. You never take the text in $objTextBox and assign it to $User.

  • Marked as answer by gonzo81 Friday, February 20, 2015 3:27 PM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 6:24pm

$User=$objtextbox.Text
Get-LogonStatistics -Identity $User |
?{$_.ApplicationId -Like "Client=MSExchangeRPC*"}| Select ClientName,ClientVersion,Latency,ApplicationId,LastAccessTime,CurrentOpenFolders |ft

February 18th, 2015 8:07pm

hi JRV and THMsRynr,

that was the solution, thank you very very much!!!! :)

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 6:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics