none
Return Array data from Invoke-Command -AsJob RRS feed

  • Question

  • Good day,

                I have been scratching my head on this problem for a couple days now and wanted to reach out for help. When I run the below code and go to receive my job, I get the error at the very bottom. "Cannot index into a null array". I've tried to create the array even before creating the 'PSCustomObject' to 'Force' it to be created as an array, within my invoke. Can anyone give me a hint as to whats going on and why my current code is not returning what I want? I am mainly worried about it returning '$table3' right now.

    ForEach ($MBX in $($MBXServers).name){
        #$session=New-PSSession -ComputerName $MBX
            $table3=@()
        $argumentlist=@($mbx,$Global:MBXPassFail,$Global:MBXMastertable,$Global:MBXCCRI)
        Write-Host -ForegroundColor Green "Working on $mbx.name..."
        $Global:MBXPassFail.Add($MBX, "MBX  Pass")
        $Global:servercount++
        $Job="Service Job" + $Global:servercount
       Invoke-Command -ComputerName $MBX  -ScriptBlock {
       Get-PSSnapin -Registered  |Add-PSSnapin;
        $P=$null;$p=@();$J=$null;$J=@();$c=$null;$C=@();$F=$null;$f=@()
        $PublicFolders=Get-PublicFolderDatabase $argumentlist[0];
        $MailboxDbs=Get-MailboxDatabase -Server $argumentlist[0];
        $MailboxSrvr=Get-MailboxServer $argumentlist[0];
        $ExchCert=Get-ExchangeCertificate -Server $argumentlist[0] | select issuer -first 1;
        $executionPolicy=Get-ExecutionPolicy;
        $eventloglevel=Get-EventLogLevel -Server $argumentlist[0] | ? {$_.eventlevel -ne "lowest"};
        IF((($PublicFolders).MountAtStartup |select -Unique) -ne $false){$PFMount = "Fail"}Else{$PFMount = "Pass"};
        IF((($PublicFolders).RetainDeletedItemsUntilBackup | select -Unique) -ne $true){$PFretain = "Fail"}Else{$PFretain = "Pass"};
        IF((($PublicFolders).AllowFileRestore |select -Unique) -ne $false){$PFrestore="Fail"}Else{$PFrestore = "Pass"};
        IF((($MailboxDbs).prohibitsendreceivequota.isunlimited  |select -Unique) -ne $True){$MBXprohibit = "Fail"}Else{$mbxprohibit = "Pass"};
        IF((($MailboxDbs).mountatstartup  |select -Unique) -ne $true){$mbxmount = "Fail"}Else{$mbxmount = "Pass"};
        IF((($MailboxDbs).retaindeleteditemsuntilbackup | select -Unique) -ne $true){$mbxretain = "Fail"}Else{$mbxretain = "Pass"};
        IF((($MailboxDbs).allowfilerestore | select -Unique) -ne $false){$MBXrestore = "Fail"}Else{$MBXrestore = "Pass"};
        IF((($MailboxDbs).circularloggingenabled  |select -Unique) -ne $false){$MBXcirc = "Fail"}Else{$mbxcirc = "Pass"};
        IF((($MailboxSrvr).messagetrackinglogenabled | select -Unique) -ne $true){$mbxlog = "Fail"}Else{$mbxlog = "Pass"};
        IF(($executionPolicy.value) -notmatch "RemoteSigned"){$execpol = "Fail"}Else{$execpol = "Pass"};
        IF(($ExchCert.Issuer) -notmatch "CN=DOD CA-28, OU=PKI, OU=DoD, O=U.S. Government, C=US"){$Exchcer = "Fail"}Else{$exchcer = "Pass"};
        IF($Errorreporting -ne $false){$errreport = "Fail"}Else{$errreport = "Pass"};
        IF($Adminlogenabled -ne $true){$adminena = "Fail"}Else{$adminena = "Pass"};
        ForEach($D in (($MailboxDbs).prohibitsendquota.value |select -Unique)){$p += ($d).ToString() + ","};
        ForEach($D in (($MailboxDbs).prohibitsendreceivequota.isunlimited  |select -Unique)){$C += ($d).ToString() + ","};
        ForEach($D in (($MailboxDbs).issuewarningquota.value |select -Unique)){$J += ($d).ToString() + ","};
        ForEach($D in ($eventloglevel)){$F += ($d).tosring() + ","};
        IF($PublicFolders -eq $null){$PFMount = "Server does not host PFs"};
                                    $table3=[pscustomobject]@{
                                                                        "Server" = $argumentlist[0]
                                                                        "EXCH-1-109 PF Mount at Startup" = $PFmount
                                                                        "EXCH-1-112 Retain Deleted Until Backup" = $PFretain
                                                                        "EXCH-1-115 Allow File Restore" = $PFRestore
                                                                        "EXCH-1-301 Prohibit Send/Receive Quota" = $($c) -replace ",",""
                                                                        "EXCH-1-303 Prohibit Send Quota" = $($p)
                                                                        "EXCH-1-306 Issue Warning Quota" = $($J) 
                                                                        "EXCH-1-309 Mount At Startup" = $mbxmount
                                                                        "EXCH-1-312 Retain Deleted Until Backup" = $mbxretain
                                                                        "EXCH-1-315 Allow File Restore" =$mbxrestore
                                                                        "EXCH-1-321 Email Forwarding" = $SMTPForward
                                                                        "EXCH-1-324 Auto Forward Enabled" = ($RemoteDomain | ? {($_.name -ne "Default") -and ($_.name -ne "com")}).autoforwardenabled | select -Unique
                                                                        "EXCH-1-802 Circular Logging Enabled" = $mbxcirc
                                                                        "EXCH-1-805 Message Tracking Log Subject Enabled" = ($MailboxSrvr).messagetrackinglogsubjectloggingenabled | select -Unique
                                                                        "EXCH-1-808 Message Tracking Log Enabled" = $mbxlog
                                                                        "EXCH-2-014 Cert Domains" = $ExchCer
                                                                        "EXCH-2-019 Execution Policy" = $execpol
                                                                        "EXCH-2-817 Event Log Level" = $($eventloglevel)
                                                                        "EXCH-2-820 Error Reporting Enabled" = $Errreport
                                                                        "EXCH-2-823 Administrator Audit Logging Enabled" = $Adminena
                                                                      };
                                    <#$argumentlist[2] += $table3;
                                    $site=(Get-ExchangeServer $argumentlist[0]).site.name;
                                    $MBXTable=[pscustomobject][ordered]@{
                                                                       "Site" = $site
                                                                       "Server" = $argumentlist[0]
                                                                       "CCRI Status" = $argumentlist[1][$argumentlist[0]]
                                                                       "STIG" = "Mailbox"
                                                                       };
                                    $MBXTable#>;
    $LogHTMLDoc=$null
    $target3 = "Mailbox" + '_CCRI' + '.html';
    $log2 = $table3 | ConvertTo-Html;
    $LogHTMLDoc = @"
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>CCRI Checker </title>
    <head>
    <style>BODY{background-color:white;}TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;background-color:LightGreen;}TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:Orange;}TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;white-space: nowrap;text-align: center;}</style>
    </head><body>
    <H2>
    <b>
    $($MBXTable.stig)
    <b/>
    <br>
    </H2>
    <P>
    $Log2
    </P>
    </body></html>
    "@;
    $path="\\__________Left Blank________\Configuration_Messaging\test\$target3";
    #Remove-Item -Path "\\__________Left Blank________\Configuration_Messaging\test\$target3"
    $LogHTMLDoc | out-file $path -Append ;
    Return $table3} -ArgumentList $argumentlist -AsJob -JobName $job 
                                                                        }
    
    
    
    ############### Error ###############
    
    Cannot index into a null array.
        + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
        + FullyQualifiedErrorId : NullArray
        + PSComputerName        : # Left Blank #
     

    Monday, September 14, 2015 6:27 PM

Answers

  • If anyone else has this issue, the answer was using Import-PSSession after creating a new session to those remote machines. It seems this is the only way to remotely manage exchange. https://technet.microsoft.com/en-us/library/hh849970.aspx?f=255&MSPPError=-2147217396
    • Marked as answer by Josh Lavely Monday, September 21, 2015 2:06 AM
    Monday, September 21, 2015 2:06 AM

All replies

  • Why would you leave out the most important part of the error.  Post the complete error message.


    \_(ツ)_/

    Monday, September 14, 2015 6:37 PM
  • #2 - Why use remoting when you have the CmdLets installed locally?


    \_(ツ)_/

    Monday, September 14, 2015 6:39 PM
  • That is the error, only I see it 8 times....

    Your second question, what do you mean? I realize some of this info is environmental, but not all of it. and I want a break down per server of their status. So, I want to run it across all 65 of our mailbox servers as quickly as I can.

    Monday, September 14, 2015 6:42 PM
  • I still have to run this same ForEach for all CAS and Transport servers. Those have more server specific checks, but this was my first 'test'. Once I can get my return data that way I want, I can move onto the next two Loops.
    Monday, September 14, 2015 6:44 PM
  • My mistake, must have slipped seeing this one; this points me to my invoke-command but I still am unsure where to look.

    
    You cannot call a method on a null-valued expression.
        + CategoryInfo          : InvalidOperation: (tosring:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
        + PSComputerName        : # Left Blank #

    Monday, September 14, 2015 6:47 PM
  • Each error has a line number and a code template with it.  Somehow you have lost or deleted this information.

    You do not want to remote a remote.  Either run the CmdLets locally or use Exchange remoting With the correct remoting setup.

    Create a simple code block or function that gets some of your info from one server and returns an object.  Next create a loop that creates one job per server.

    After that you wait on the jobs and collect and format the report

    Start small and build in layers until you understand how this works.  Your method is convoluted and will make the whole task harder.


    \_(ツ)_/

    Monday, September 14, 2015 6:51 PM
  • I tried making my Array a 'Global' array so it could become available outside my invoke to no avail :-(
    Monday, September 14, 2015 6:53 PM
  • My Foreach loop ran perfectly (very slow though), until I dished it out as a job. It populates the data into my variables from the remote machine but will not fill the array. I understand how a foreach and invoke-command works, I am trying to use them together and return an array of information (as you can see). What do you mean by 'You do not want to remote a remote'? I have definitely started small with this and I am at its 'final' stages now. I began just as you said, starting small with tiny bits of information. It led me to building the array and getting exactly what I wanted, with a caveat; that info wouldn't be available for 25+ hours.
    Monday, September 14, 2015 6:59 PM
  • You cannot run things the way you are and you need to simplify to sort out al of your issues.

    Always separate the script block so it satys indepp-endent. This is a reminder to you that it is NOT part of the current seeison.

    Example:

    ForEach ($MBX in $($MBXServers).name) {
    	
    	$argumentlist = @($mbx, $Global:MBXPassFail, $Global:MBXMastertable, $Global:MBXCCRI)
    	Write-Host -ForegroundColor Green "Working on $mbx.name..."
    	Invoke-Command -ComputerName $MBX -ScriptBlock $sb -ArgumentList $argumentlist -AsJob -JobName $mbx
    }
    

    Define the $SB outside of the loop and test it stand aloneuntilit works.

    To execute a script block use $sb.Invoke($argumentlist)

    If you are not using Exchaneg remoting then sstart simple with this SB:

    $sb={
        Add-PSSnapin
        Get-PublicFolderDatabase $args[0]
    }

    Just run that much and make it work.  Once you can run that then build your job loop and test that.

    After all of the control pieces are tested then add a couple of lines at a time to your script block and test.


    \_(ツ)_/


    • Edited by jrv Monday, September 14, 2015 7:05 PM
    Monday, September 14, 2015 7:02 PM
  • Do not format your output in the jobs. Return the objects and build report externally.  It is easier to debug and control.  Your approach is fighting every advantage that objects systems offer.


    \_(ツ)_/

    Monday, September 14, 2015 7:05 PM
  • Actually your loop should look like this:

    ForEach ($server in $MBXServers) {
    	Write-Host -ForegroundColor Green "Working on $mbx.name..."
    	Invoke-Command -ComputerName $server.Name -ScriptBlock $sb -ArgumentList $mbx -AsJob -JobName $server.Name
    }

    You cannot pass globals to Invoke.  You can pass the value but you cannot change it in an Invoke or a job.

    Remember that the script block must be independent except for the arguments and can only return data to Receive-Job.


    \_(ツ)_/


    • Edited by jrv Monday, September 14, 2015 7:09 PM
    Monday, September 14, 2015 7:08 PM
  • Thank  your time and help, ill give all of this a go and report back. I do like the concept of keeping my Script Block separate; clean things up a bit. Although I think I may have found the problem area. Either way ill let you know!.
    Tuesday, September 15, 2015 12:09 PM
  • When I run $sb.Invoke($argumentlist) through the foreach this works...

    ForEach ($Server in $MBXServers){
            $argumentlist=@($MBX)
            Write-Host -ForeGroundColor Green "Wokring on $mbx..."
           $array+=$sb.Invoke($argumentlist)
                                   {
            
    

    But, when revert back to

    Invoke-command -computername $mbx -ScriptBlock $sb -Argumentlist $argumentlist -AsJob -JobName $job

    This is when I receive the 'Cannot index into o Null array errors.... It seems like its an issue with handling these requests as jobs.

    
    Tuesday, September 15, 2015 12:43 PM
  • This is my current Loop. Thanks again for the help.
    $array=$null
    $array=@()
    $MBXServers = $null
    $Global:servercount=$null
    $MBXServers = (Get-MailboxServer).name 
    ForEach ($MBX in $MBXServers){
         $argumentlist=@($mbx)
         Write-Host -ForegroundColor Green "Working on $mbx..."
         $Global:servercount++
         $Job="Service Job" + $Global:servercount
         $sb={
       Get-PSSnapin -Registered  |Add-PSSnapin;
       $table3=$null
        $P=$null;$p=@();$J=$null;$J=@();$c=$null;$C=@();$F=$null;$f=@()
        $PublicFolders=Get-PublicFolderDatabase $argumentlist[0];
        $MailboxDbs=Get-MailboxDatabase -Server $argumentlist[0];
        $MailboxSrvr=Get-MailboxServer $argumentlist[0];
        $ExchCert=Get-ExchangeCertificate -Server $argumentlist[0] | select issuer -first 1;
        $executionPolicy=Get-ExecutionPolicy;
        $eventloglevel=Get-EventLogLevel -Server $argumentlist[0]| ? {$_.eventlevel -ne "lowest"};
        IF((($PublicFolders).MountAtStartup |select -Unique) -ne $false){$PFMount = "Fail"}Else{$PFMount = "Pass"};
        IF((($PublicFolders).RetainDeletedItemsUntilBackup | select -Unique) -ne $true){$PFretain = "Fail"}Else{$PFretain = "Pass"};
        IF((($PublicFolders).AllowFileRestore |select -Unique) -ne $false){$PFrestore="Fail"}Else{$PFrestore = "Pass"};
        IF((($MailboxDbs).prohibitsendreceivequota.isunlimited  |select -Unique) -ne $True){$MBXprohibit = "Fail"}Else{$mbxprohibit = "Pass"};
        IF((($MailboxDbs).mountatstartup  |select -Unique) -ne $true){$mbxmount = "Fail"}Else{$mbxmount = "Pass"};
        IF((($MailboxDbs).retaindeleteditemsuntilbackup | select -Unique) -ne $true){$mbxretain = "Fail"}Else{$mbxretain = "Pass"};
        IF((($MailboxDbs).allowfilerestore | select -Unique) -ne $false){$MBXrestore = "Fail"}Else{$MBXrestore = "Pass"};
        IF((($MailboxDbs).circularloggingenabled  |select -Unique) -ne $false){$MBXcirc = "Fail"}Else{$mbxcirc = "Pass"};
        IF((($MailboxSrvr).messagetrackinglogenabled | select -Unique) -ne $true){$mbxlog = "Fail"}Else{$mbxlog = "Pass"};
        IF(($executionPolicy.value) -notmatch "RemoteSigned"){$execpol = "Fail"}Else{$execpol = "Pass"};
        IF(($ExchCert.Issuer) -notmatch "CN=DOD CA-28, OU=PKI, OU=DoD, O=U.S. Government, C=US"){$Exchcer = "Fail"}Else{$exchcer = "Pass"};
        IF($Errorreporting -ne $false){$errreport = "Fail"}Else{$errreport = "Pass"};
        IF($Adminlogenabled -ne $true){$adminena = "Fail"}Else{$adminena = "Pass"};
        ForEach($D in (($MailboxDbs).prohibitsendquota.value |select -Unique)){$p += ($d).ToString() + ","};
        ForEach($D in (($MailboxDbs).prohibitsendreceivequota.isunlimited  |select -Unique)){$C += ($d).ToString() + ","};
        ForEach($D in (($MailboxDbs).issuewarningquota.value |select -Unique)){$J += ($d).ToString() + ","};
        ForEach($D in ($eventloglevel)){$F += ($d).tosring() + ","};
        IF($PublicFolders -eq $null){$PFMount = "Server does not host PFs"};
                                    $table3=[pscustomobject][ordered]@{
                                                                        "Server" = $argumentlist[0]
                                                                        "EXCH-1-109 PF Mount at Startup" = $PFmount
                                                                        "EXCH-1-112 Retain Deleted Until Backup" = $PFretain
                                                                        "EXCH-1-115 Allow File Restore" = $PFRestore
                                                                        "EXCH-1-301 Prohibit Send/Receive Quota" = $($c) -replace ",",""
                                                                        "EXCH-1-303 Prohibit Send Quota" = $($p)
                                                                        "EXCH-1-306 Issue Warning Quota" = $($J) 
                                                                        "EXCH-1-309 Mount At Startup" = $mbxmount
                                                                        "EXCH-1-312 Retain Deleted Until Backup" = $mbxretain
                                                                        "EXCH-1-315 Allow File Restore" =$mbxrestore
                                                                        "EXCH-1-321 Email Forwarding" = $SMTPForward
                                                                        "EXCH-1-324 Auto Forward Enabled" = ($RemoteDomain | ? {($_.name -ne "Default") -and ($_.name -ne "com")}).autoforwardenabled | select -Unique
                                                                        "EXCH-1-802 Circular Logging Enabled" = $mbxcirc
                                                                        "EXCH-1-805 Message Tracking Log Subject Enabled" = ($MailboxSrvr).messagetrackinglogsubjectloggingenabled | select -Unique
                                                                        "EXCH-1-808 Message Tracking Log Enabled" = $mbxlog
                                                                        "EXCH-2-014 Cert Domains" = $ExchCer
                                                                        "EXCH-2-019 Execution Policy" = $execpol
                                                                        "EXCH-2-817 Event Log Level" = $($eventloglevel)
                                                                        "EXCH-2-820 Error Reporting Enabled" = $Errreport
                                                                        "EXCH-2-823 Administrator Audit Logging Enabled" = $Adminena
                                                                      };
                                    <#$argumentlist[2] += $table3;
                                    $site=(Get-ExchangeServer $mbx).site.name;
                                    $MBXTable=[pscustomobject][ordered]@{
                                                                       "Site" = $site
                                                                       "Server" = $mbx
                                                                       "CCRI Status" = $argumentlist[1][$mbx]
                                                                       "STIG" = "Mailbox"
                                                                       };
                                    $MBXTable#>;
    $LogHTMLDoc=$null
    $target3 = "Mailbox" + '_CCRI' + '.html';
    $log2 = $table3 | ConvertTo-Html;
    $LogHTMLDoc = @"
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>CCRI Checker </title>
    <head>
    <style>BODY{background-color:white;}TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;background-color:LightGreen;}TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:Orange;}TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;white-space: nowrap;text-align: center;}</style>
    </head><body>
    <H2>
    <b>
    $($MBXTable.stig)
    <b/>
    <br>
    </H2>
    <P>
    $Log2
    </P>
    </body></html>
    "@;
    $path="\\\Configuration_Messaging\test\$target3";
    #Remove-Item -Path "\\\Configuration_Messaging\test\$target3"
    $LogHTMLDoc | out-file $path -Append ;
    Return $table3} 
         #$Array += $sb.Invoke($argumentlist)
         Invoke-Command -ComputerName $mbx -ScriptBlock $sb -ArgumentList $argumentlist -AsJob -JobName $job -Debug
         
                                          }
    ##### job Counter #####
    $Global:failedJobs=@()
    $Global:Machines=@()
    Do{
    $Global:Running = Get-Job | ? {($_.state -eq "Running") -and $_.Name -like "Service Job*"}
    $Global:Completed = Get-Job | ? {($_.state -ne "Running") -and $_.Name -like "Service Job*"}
    ForEach($RecJob in $Global:Completed){
    if ($RecJob.state -eq "Failed" )
        {
            $Global:failedJobs += $recjob.location
            Remove-job $RecJob.id
            $Global:Completedcounter ++   
        }
    Else{ 
            Write-Host -ForegroundColor Green "Collecting Data from : " $RecJob.location
            $Array += Receive-Job $recjob
            Remove-job $RecJob.id 
        }
                                         }
      }
    Until($Global:Completed -eq $null -and $Global:Running -eq $null)

    Tuesday, September 15, 2015 1:23 PM
  • you didn't do what I asked.  YOu jsst moved some things around and are making the exact same bunch of mistakes.

    Start with the script block I posted and test that as I posted.

    Run this in the loop as an Invoke-command
    $sb={
       
    Add-PSSnapin
       
    Get-PublicFolderDatabase$args[0]
    }

    ForEach ($server in$MBXServers) {
        Write-Host -ForegroundColor Green "Working on $mbx.name..."
        Invoke-Command -ComputerName$server.Name -ScriptBlock$sb -ArgumentList$mbx -AsJob -JobName$server.Name
    }

    You keep making changes that just revert you back to the same set of mistakes.  Learnwhat is happening by getting the structure first.  After this works then add a few lines at a time to the script block.


    \_(ツ)_/


    • Edited by jrv Tuesday, September 15, 2015 2:58 PM
    Tuesday, September 15, 2015 2:58 PM
  • I will take your advice and rebuild my loop. Thank you.
    Tuesday, September 15, 2015 3:18 PM
  • Update: Ive found there is no problems with my $sb or how im using it/ collecting data within. When I run just h einvoke all data I expect is returned. The issue appears to only be when running invoke -AsJob and trying to pass exchange cmdlets. Even when I load the Snappin or launch EMS remotely, the issue still exists. I am running Powershell V3 across all my servers. This is a very interesting problems, very specific to -AsJob and Exchange cmdlets.
    Friday, September 18, 2015 11:56 AM
  • I gave you a script block to test with and an instruction on how to build up and debug your sb.  If you do that you will find the problem.  If you just ignore the advice then you are on you own.


    \_(ツ)_/

    Friday, September 18, 2015 3:57 PM
  • I did what you advised, but the bottom line is, its not a problem with my script block, its a problem running exchange cmdlets from the remote machine. Even if all I have in my sb was {Get-MailboxServer} or any other Exchange specific cmdlet, it fails and screams about 'serverSettings'. It is not a problem with my script block. I'm wondering why I can't pass any exchange cmdlets through invoke-command; even with -Session, connecting via URI (to Microsoft.Exchange on the remote server).

    Ive looked at my PSSessionConfigurations and x32 and x64 are listed, I do not have trusted hosts, all machines are inside my domain using Kerb.,ran winrm quickconfig, ive verified PSRemoting is $True on these machines, ive verified PSVersion 3.0 is on these machines.  So im a little stuck at the moment. 


    When I pass through to load the snap-ins and 'get-command *mail*' I see plenty of exchange cmdlets being returned as viable options, but they cannot be used.
    • Edited by Josh Lavely Friday, September 18, 2015 5:35 PM Spelling
    Friday, September 18, 2015 5:34 PM
  • What is the message if you run the exact sb that I posted.

    Just run the invoke against one server

    $sb={
        
    Add-PSSnapin  Microsoft.Exchange.Management.PowerShell.E2010
        
    Get-Mailbox
    }

    Invoke-Command -ComputerName  <remoteserver> -ScriptBlock $sb

    Just  run that.  What is the message returned?  If you are using other than 2010 then change the snapin name.


    \_(ツ)_/

    Friday, September 18, 2015 5:53 PM
  • If anyone else has this issue, the answer was using Import-PSSession after creating a new session to those remote machines. It seems this is the only way to remotely manage exchange. https://technet.microsoft.com/en-us/library/hh849970.aspx?f=255&MSPPError=-2147217396
    • Marked as answer by Josh Lavely Monday, September 21, 2015 2:06 AM
    Monday, September 21, 2015 2:06 AM
  • That is true but has nothing to do  with your original issues.


    \_(ツ)_/

    Monday, September 21, 2015 2:09 AM