remoting and Import-CliXml error

by oogabooga at 2012-09-06 09:49:23

I have a script that does reporting against an XML file that I have data rolled up into every week. I’ve simplified it here:

[code2=powershell]param ($days = 30)

$LogLocation = 'c:\scripts\ActiveSyncData'
cd $LogLocation
$mostrecent = ls ActiveSyncUserData*.xml | sort -Property lastwritetime -Descending | select -First 1
$data = Import-Clixml $mostrecent

$data | select -first 2[/code2]

When I run that code locally on the server, it looks like this:

[code2=powershell]PS C:\scripts> .\test.ps1

Date : 7/31/2012 12:00:00 AM
Username : ana.bobanna
AccountStatus : Enabled
DeviceID : Appl8801111
DeviceType : iPhone
ItemsSent : 360
ItemsReceived : 7
Hits : 591
EmailsSent : 351
EmailsReceived : 0
CalendarSent : 9
CalendarReceived : 1
Server : EUMSGMAIL001

Date : 7/31/2012 12:00:00 AM
Username : dimitar.avatar
AccountStatus : Enabled
DeviceID : Appl7S12222
DeviceType : iPhone
ItemsSent : 1004
ItemsReceived : 31
Hits : 1349
EmailsSent : 946
EmailsReceived : 1
CalendarSent : 7
CalendarReceived : 1
Server : EUMSGMAIL001[/code2]

When I run it remotely, it throws all kinds of strange errors:

[code2=powershell]PS C:> Invoke-Command SERVERNAME -Credential $cred { c:\scripts\test.ps1 }
Exception of type 'System.OutOfMemoryException' was thrown.
+ CategoryInfo : NotSpecified: (:slight_smile: [Import-Clixml], OutOfMemoryException
+ FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.ImportClixmlCommand

PS C:> Invoke-Command SERVERNAME -Credential $cred { c:\scripts\test.ps1 }
Processing data for a remote command failed with the following error message: The WSMan provider host process did not r
eturn a proper response. A provider in the host process may have behaved improperly. For more information, see the abo
ut_Remote_Troubleshooting Help topic.
+ CategoryInfo : OperationStopped: (System.Manageme…pressionSyncJob:PSInvokeExpressionSyncJob) , PSRe
+ FullyQualifiedErrorId : JobFailure

PS C:> Invoke-Command SERVERNAME -Credential $cred { c:\scripts\test.ps1 }
Processing data for a remote command failed with the following error message: <f:WSManFault xmlns:f="http://schemas.mic" Code="3762507597" Machine="SERVERNAME"><f:Message><f:ProviderFault provider="micr
osoft.powershell" path="C:\Windows\system32\pwrshplugin.dll"></f:ProviderFault></f:Message></f:WSManFault> For more inf
ormation, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OperationStopped: (System.Manageme…pressionSyncJob:PSInvokeExpressionSyncJob) , PSRe
+ FullyQualifiedErrorId : JobFailure[/code2]

I can run normal remoting commands and scripts fine.

[code2=powershell]PS C:&gt; Invoke-Command SERVERNAME -Credential $cred { ls c:\scripts\ }

Directory: C:\scripts

Mode LastWriteTime Length Name PSComputerName
---- ------------- ------ ---- --------------
d---- 9/6/2012 10:31 AM ActiveSyncData SERVERNAME
d---- 8/24/2012 10:09 AM modules SERVERNAME
d---- 9/6/2012 10:41 AM test SERVERNAME
-a— 8/23/2012 1:39 PM 5042 Audit-SensitiveGroups.ps1 SERVERNAME
-a— 9/6/2012 10:03 AM 2404 Get-ActiveSyncUsageReport.ps1 SERVERNAME
-a— 9/5/2012 3:55 PM 4749 Get-ALLActiveSyncLogs.ps1 SERVERNAME
-a— 8/20/2012 4:04 PM 326 splunk-svc-ScriptUser-unpri.cred SERVERNAME
-a— 8/29/2012 3:09 PM 326 splunk.cred SERVERNAME
-a— 9/6/2012 11:39 AM 248 test.ps1 SERVERNAME[/code2]

I remotely run a script on this box that then runs a remote scriptblock on all my activesync servers to collect the logs, copy them over, export to XML, and that runs just fine also.

What’s going on here with Import-CliXml?

The host machine is Windows 2008 R2 w/SP1
For the clients, I’ve tried 2008 R2 w/SP1 (Powershell v2) and Windows 7 Professional (Powershell v3). Same results.
by oogabooga at 2012-09-06 10:05:49
Just to add a little more information. I think this might be related to me pulling in data remotely that has already been pulled in and exported remotely.

For example, I can save the results of a directory listing into an XML file, and then Import-CliXml those results remotely no problem. Just not my custom object that I created from other remoting objects.

Here is the imported object that is broken when trying to retrive via remoting:

[code2=powershell]PS C:\scripts> $boo = .\test.ps1

PS C:\scripts\ActiveSyncData> $boo | gm

TypeName: Selected.System.Management.Automation.PSCustomObject

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AccountStatus NoteProperty System.String AccountStatus=Enabled
CalendarReceived NoteProperty System.String CalendarReceived=1
CalendarSent NoteProperty System.String CalendarSent=9
Date NoteProperty System.DateTime Date=7/31/2012 12:00:00 AM
DeviceID NoteProperty System.String DeviceID=Appl88001111
DeviceType NoteProperty System.String DeviceType=iPhone
EmailsReceived NoteProperty System.String EmailsReceived=0
EmailsSent NoteProperty System.String EmailsSent=351
Hits NoteProperty System.String Hits=591
ItemsReceived NoteProperty System.String ItemsReceived=7
ItemsSent NoteProperty System.String ItemsSent=360
Server NoteProperty System.String Server=EUMSGMAIL001
Username NoteProperty System.String Username=ana.bobanna[/code2]
by oogabooga at 2012-09-06 10:57:49
The problem ended up being the size of the data set. The full object count that didn’t work:
[code2=powershell]PS C:\scripts> $export.count

If I whittled down my export to 1 month and then try the remoting job, that works fine.
[code2=powershell]PS C:\scripts> $reportdata.count

It’s really not that much data in memory. 201mb to be exact. I started doing some digging and it turns out that WSman is set to 150mb max. I set it to 512 on this server:

set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
by poshoholic at 2012-09-07 05:18:42
Glad you worked it out, and thanks for coming back to share your solution.
by sxavier at 2013-05-10 02:12:38
I do have the same issue. I have tried the following query
[code]set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512[/code]
but not yet solved. Can someone please guide me?