Author Posts

September 19, 2013 at 9:28 am

trying to create an object on a remote session but is failing. Any idea ?

PS> $sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “http://server/Power
Shell” -Authentication Kerberos -Credential $cred -ErrorAction Stop
PS> Enter-PSSession $sess
[server]: PS>new-object

writeErrorStream : True
Exception : System.Management.Automation.RemoteException: The term 'New-Object' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the spelling of the nam
e, or if a path was included, verify that the path is correct and try again.
at System.Management.Automation.PowerShell.CoreInvokeRemoteHelper[TInput,TOutput](PSDataC
ollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1
input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataC
ollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.RemotePipeline.Invoke(IEnumerable input)
at Microsoft.PowerShell.Executor.ExecuteCommandHelper(Pipeline tempPipeline,

September 19, 2013 at 9:36 am

The session is constrained and I don't think it has new-object available. Rather than entering the session – use import-possession to make proxy functions of the Exchange cmdlets and work with them that way

September 19, 2013 at 10:06 am

how can i create an unconstrained session ?

September 19, 2013 at 10:09 am

With very great difficulty

The Exchange team designed their PowerShell implementation to be deliberately constrained when accessed remotely. As I stated earlier the best way is to create the session and then use import-pssession.

That is the way it is designed to work and that is the way that works best. I have spent a lot of time accessing Exchange remotely and think I've tried most options. Importing the session is the cleanest way to work

September 19, 2013 at 10:33 am

Any idea what changes can i make to the below code to make it work ?

$Mbxservers=Get-MailboxServer name*
Foreach ($server in $mbxservers)
$sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “http://$server/PowerShell” -Authentication Kerberos -Credential $cred -ErrorAction Stop
$arrayJobs += Invoke-Command {

$report = @()
$mailboxes = @(Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -server $serverName -ResultSize unlimited)
foreach ($mb in $mailboxes)
$stats = $mb | Get-MailboxStatistics | Select-Object TotalItemSize,TotalDeletedItemSize,ItemCount,LastLogonTime,LastLoggedOnUserAccount
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $mb.DisplayName
$userObj | Add-Member NoteProperty -Name "Last Logon By" -Value $stats.LastLoggedOnUserAccount
$userObj | Add-Member NoteProperty -Name "Item Size (Mb)" -Value $stats.TotalItemSize.Value.ToMB()
$userObj | Add-Member NoteProperty -Name "Deleted Item Size (Mb)" -Value $stats.TotalDeletedItemSize.Value.ToMB()
$userObj | Add-Member NoteProperty -Name "Items" -Value $stats.ItemCount
$userObj | Add-Member NoteProperty -Name "Type" -Value $mb.RecipientTypeDetails
$userObj | Add-Member NoteProperty -Name "Server" -Value $mb.ServerName
$userObj | Add-Member NoteProperty -Name "Database" -Value $mb.Database
$report = $report += $userObj
} -asjob -Session $sess

September 19, 2013 at 11:05 am

I'd look at something like this. can't guarantee its 100% as I don't have an Exchange server handy to test

$Mbxservers=Get-MailboxServer name*
Foreach ($server in $mbxservers)
$sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “http://$server/PowerShell” -Authentication Kerberos -Credential $cred -ErrorAction Stop
import-pssession $sess
$report = @()
$mb = Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -server $serverName -ResultSize unlimited
$mb | Get-MailboxStatistics |
Select-Object @{N="DisplayName"; E={$mb.DisplayName}},
@{N="Item Size (Mb)"; E={$_.TotalItemSize.Value.ToMB()}},
@{N="Deleted Item Size (Mb)"; E={$_.TotalDeletedItemSize.Value.ToMB()}},
@{N="Type"; E={$mb.RecipientTypeDetails}},
@{N="Server"; E={$mb.ServerName}},
@{N="Database"; E={$mb.Database}}