title: Error uploading many reports RDL in SSRS 2008 using Powershell
body: <p>I have Windows 2008 Server 64 bits, Sql Server Reporting Services 2008 R2.
  I use ReportService web Service to upload RDLs files. I use script ps1 Powershell for upload reports like:</p>
  
  <p><a href="http://randypaulo.wordpress.com/2012/02/21/how-to-install-deploy-ssrs-rdl-using-powershell/" rel="nofollow noreferrer">http://randypaulo.wordpress.com/2012/02/21/how-to-install-deploy-ssrs-rdl-using-powershell/</a></p>
  
  <p>I get errors when uploading reports. The first 5 rdls is uploaded right, but next wrong. 
  <strong>REP_ACCESO_AIRNET04_R_09, REP_ACCESO_AIRNET04_R_10, REP_ACCESO_AIRNET04_R_11</strong>, <code>REP_ACCESO_AIRNET04_R_12</code> are uploaded right.</p>
  
  <p><code>REP_ACCESO_AIRNET04_R_13</code> not, then I get the error.</p>
  
  <p>If use 3-4 reports rdl, not problem. But using more rdls files, I get errors.</p>
  
  <p>I check SQL Server Reporting Services and it is running</p>
  
  <p>I get several errors in powershell, that uses my script ps1 to install - upload reports rdls in SSRS:</p>
  
  <pre><code>Exception of type 'System.OutOfMemoryException' was thrown.
  
  Failed. The error was: 'Error al procesar los datos de un comando remoto. Mensa
  je de error: &lt;f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/w
  smanfault" Code="3762507597" Machine="DESCASRPSW01"&gt;&lt;f:Message&gt;&lt;f:ProviderFault
   provider="microsoft.powershell" path="C:\Windows\system32\pwrshplugin.dll"&gt;&lt;/f
  :ProviderFault&gt;&lt;/f:Message&gt;&lt;/f:WSManFault&gt; Para obtener m s informaci¢n, consul
  te el tema de la Ayuda about_Remote_Troubleshooting.'.
  
  
  Failed. The error was: 'Error al procesar los datos de un comando remoto. Mensa
  je de error: The WSMan provider host process did not return a proper response. 
   A provider in the host process may have behaved improperly. Para obtener m s i
  nformaci¢n, consulte el tema de la Ayuda about_Remote_Troubleshooting.'.
  </code></pre>
  
  <p>And logs in  c:\Program Files\Microsoft SQL Server\MSRS10_50.REPORTING\Reporting Services\LogFiles</p>
  
  <blockquote>
    <p>library!ReportServer_0-107!1118!08/09/2012-08:46:59:: Call to
    SetItemDataSourcesAction(/Reale/REP_ACCESO_AIRNET04_R_12).</p>
    
    <p>webserver!ReportServer_0-107!7fc!08/09/2012-08:47:11:: i INFO:
    Reporting Web Server stopped
    appdomainmanager!DefaultDomain!14c!08/09/2012-08:47:16:: i INFO:
    Appdomain:152 ReportServer_REPORTING_0-107-129889682211300455
    unregistered.</p>
  </blockquote>
  
  <p>I active VERBOSE log and this messages key for me:</p>
  
  <ul>
  <li>ReportServer_REPORTING_0-1-129889760220267707 is about to be
  unloaded.  </li>
  <li>ShutDownMessage: Change Notification for critical
  directories. bin dir change or directory rename</li>
  <li>HostingEnvironment   initiated shutdown  </li>
  <li>Change Notification for critical directories.  </li>
  <li>INFO: Reporting Web Server stopped  </li>
  <li>ReportServer_REPORTING_0-1-129889760220267707 unregistered.</li>
  </ul>
  
  <p>pipeline=0x0000000000F1FA30, id=13907115651467581232, connid=13907115650930710318 ...</p>
  
  <p>runningrequests!ReportServer_0-1!123c!08/09/2012-11:06:57:: v VERBOSE: User map'DESCASRPSW01\instalador
  <a href="http://descasrpsw01/ReportServer_REPORTING/ReportService2005.asmx?WSDL" rel="nofollow noreferrer">http://descasrpsw01/ReportServer_REPORTING/ReportService2005.asmx?WSDL</a>1'</p>
  
  <p>rshost!rshost!123c!08/09/2012-11:06:57:: v VERBOSE: HttpPipelineCallback::EndOfRequest(): continue pipeline=0x0000000000F1FA30.</p>
  
  <p>rshost!rshost!e3c!08/09/2012-11:06:57:: v VERBOSE: HttpPipeline::DisconnectCallback: releasing pipeline=0x0000000000F1FA30.</p>
  
  <p>rshost!rshost!fbc!08/09/2012-11:06:57:: v VERBOSE: ThreadContinuePipeline: processing request on pipeline=0x0000000000F1FA30, state=2, IOError=0, node=0.</p>
  
  <p>rshost!rshost!fbc!08/09/2012-11:06:57:: v VERBOSE: State machine disconnected pipeline=0x0000000000F1FA30, state=4 ...</p>
  
  <p>rshost!rshost!fbc!08/09/2012-11:06:57:: v VERBOSE: HttpPipeline::DoStateDisconnected: releasing pipeline=0x0000000000F1FA30.</p>
  
  <p>rshost!rshost!fbc!08/09/2012-11:06:57:: v VERBOSE: HttpPipeline::ReleaseOnce: releasing pipeline=0x0000000000F1FA30.</p>
  
  <p>rshost!rshost!fbc!08/09/2012-11:06:57:: v VERBOSE: Destroying pipeline=0x0000000000F1FA30, callback=0x0000000000F1C660 ...</p>
  
  <p>appdomainmanager!ReportServer_0-1!13e4!08/09/2012-11:07:03:: v VERBOSE: Appdomain:3 ReportServer_REPORTING_0-1-129889760220267707 is about to be unloaded. </p>
  
  <p>ShutDownMessage: Change Notification for critical directories.</p>
  
  <p>bin dir change or directory rename</p>
  
  <p>HostingEnvironment initiated shutdown</p>
  
  <p>Change Notification for critical directories.</p>
  
  <p>bin dir change or directory rename</p>
  
  <p>Change Notification for critical directories.</p>
  
  <p>bin dir change or directory rename</p>
  
  <p>Change Notification for critical directories.</p>
  
  <p>bin dir change or directory rename</p>
  
  <p>webserver!ReportServer_0-1!13e4!08/09/2012-11:07:03:: i INFO: Reporting Web Server stopped</p>
  
  <p>appdomainmanager!DefaultDomain!b30!08/09/2012-11:07:08:: i INFO: Appdomain:3 ReportServer_REPORTING_0-1-129889760220267707 unregistered.</p>
  
  <p>rshost!rshost!b30!08/09/2012-11:07:08:: i INFO: Application domain type ReportServer 
  statistics: created: 1, unloaded: 1, failed: </p>
  
  <p><strong>UPDATE</strong>: the problem-issue is using PSRemoting and Get-Content for get bytes of a RDL file.
  The same script ps1 without PSRemoting is right.</p>
  
  <p>For some RDL files, I get error using psremoting.</p>
  
  <pre><code>#Load the RDL Binary 
  [Byte[]]$rptContent = Get-Content $rptReference -Encoding byte
  </code></pre>
  
  <p>Solution: use <strong>[System.IO.File]::ReadAllBytes($sourceFile)</strong></p>
  
  <p>References:</p>
  
  <p><a href="http://www.vistax64.com/powershell/203663-get-content-encoding-byte-problem-v1-v2-ctp3.html" rel="nofollow noreferrer">http://www.vistax64.com/powershell/203663-get-content-encoding-byte-problem-v1-v2-ctp3.html</a></p>
  
  <p>Get-Content is very memory hungry and inefficient when loading binary file. Every byte gets wrapped intoPSObject. I suggest to use .Net functions (.Net v4 has File.ReadAllBytes method) – @user1578107 </p>
  
  <p><a href="https://stackoverflow.com/questions/5030483/powershell-ftp-send-large-file-system-outofmemoryexception">Powershell FTP Send large file System.OutOfMemoryException</a> </p>
  
  <p>"Having hit a similar issue myself with RAM usage hitting the GB's uploading a 3MB file, I found that replacing:"</p>
  
  <pre><code> $content = gc -en byte $sourceFile
  </code></pre>
  
  <p>With:</p>
  
  <pre><code> $content = [System.IO.File]::ReadAllBytes($sourceFile)
  </code></pre>