Author Posts

May 19, 2013 at 5:16 am



I'm trying the following after I have startet a new  "Import-PSSession $Session"

$sb = {(Get-MailboxStatistics -Identity $Mailbox.Alias).TotalItemSize.value.ToBytes()}
[int]$MailboxSize = Invoke-Command -Session $session -ScriptBlock $sb

But I get the error that Identity is empty.

How can I pass the content of the variable with the invoke command?
Or another way of putting it, what am I doing wrong?

Regards Lars Mortensen

May 19, 2013 at 6:09 am

use the argumentlist parameter on invoke-command

$sess = New-PSSession -ComputerName $env:COMPUTERNAME
Invoke-Command -Session $sess -ScriptBlock {param ($procname) Get-Process -Name $procname} -ArgumentList powerShell

May 19, 2013 at 11:21 am


Thank you for the answer, but I can't seam to make it work.

My code is now:
$sb = {param ($Mailbox) (Get-MailboxStatistics -Identity $Mailbox.Alias).TotalItemSize.value.ToBytes()}
[int]$MailboxSize = Invoke-Command -Session $session -ScriptBlock $sb -ArgumentList powerShell

Regards Lars.

May 19, 2013 at 11:26 am

The example I gave used PowerShell as process name

In your case you need to give a mailbox identifier – a name or an alias

May 25, 2013 at 1:05 am


Im not sure what you mean.

I do supply a mailbox identifier: $Mailbox.Alias

PS M:\SkyDriveBackup\SkyDrive\BackupScripts> echo $Mailbox.Alias

PS M:\SkyDriveBackup\SkyDrive\BackupScripts> $sb = {param ($Mailbox) (Get-MailboxStatistics -Identity $Mailbox.Alias).TotalItemSize.value.ToBytes()}

PS M:\SkyDriveBackup\SkyDrive\BackupScripts> [int]$MailboxSize = Invoke-Command -Session $session -ScriptBlock $sb -ArgumentList powerShell
Cannot bind argument to parameter 'Identity' because it is null.     + CategoryInfo          : InvalidData: (:) [Get-MailboxStatistics], ParameterBindingValidationException     + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxStatistics     + PSComputerName        : 4twexbe1

PS M:\SkyDriveBackup\SkyDrive\BackupScripts> echo  $MailboxSize

May 25, 2013 at 1:14 am

Found the error now, this Works:

$sb = {param ($MailAlias) (Get-MailboxStatistics -Identity $($MailAlias)).TotalItemSize.value.ToBytes()}
[int]$MailboxSize = Invoke-Command -Session $session -ScriptBlock $sb -ArgumentList $Mailbox.Alias



Regards Lars