title: Powershell convert value to type "System32 error
body: <p>I writing a script in Powershell to gather information about how many files are in my archive folder, the script is to count the files in the folder then it deletes file older than give date and then it counts the number of files again to report how many files it deleted. </p>
  
  <p>I can get this to work however I am running into a little problem with the syntax. When I have it like this it works fine.</p>
  
  <pre><code>Clear-Host
  
  $ErrorFiles = "c:\data\ErrorFiles"
  $Archivefiles = "c:\data\Archivefiles"
  
  $PreCountErrorFiles = ((Get-ChildItem $ErrorFiles | Measure-Object).Count)
  $PreCountArchivefiles = ((Get-ChildItem $Archivefiles | Measure-Object ).Count)
  
  Get-ChildItem $ErrorFiles  | Where  {$_.LastWriteTime –lt ((Get-Date).AddDays(-10) )}  | ForEach { Remove-Item $_.FullName }
  Get-ChildItem $Archivefiles | Where  {$_.LastWriteTime –lt ((Get-Date).AddDays(-10) )}  | ForEach { Remove-Item $_.FullName }
  
  $PostCountErrorFiles = ((Get-ChildItem $ErrorFiles | Measure-Object).Count)
  $PostCountArchivefiles  = ((Get-ChildItem $Archivefiles | Measure-Object ).Count)
  
  
  $str1 = "Number of files in " + $ErrorFiles.ToString() + " was " + $PreCountErrorFiles.ToString() + " number of files deleted " + ($PreCountErrorFiles - $PostCountErrorFiles).ToString() + " and "  + $PostCountErrorFiles.ToString() + " are left." + "`n"  
  $str2 = "Number of files in " + $Archivefiles.ToString() + " was " + $PreCountArchivefiles.ToString() + " number of files deleted " + ($PreCountArchivefiles - $PostCountArchivefiles).ToString() + " and "          + $PostCountArchivefiles.ToString() + " are left." + "`n"
  
  write-host $str1
  write-host $str2
  </code></pre>
  
  <p>However if I try to change the #str1 assignment to have it in one line and take both the strings I get this error (see code below)</p>
  
  <p>Cannot convert value "Number of files in" to type "System.Int32". Error: "Input string was not in a correct format."
  At line:13 char:1
  + $str1 = "Number of files in " + $ErrorFiles.ToString() + " was " + $PreCountErro ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvalidCastFromStringToInteger</p>
  
  <pre><code>Clear-Host
  
  $ErrorFiles = "c:\data\ErrorFiles"
  $Archivefiles = "c:\data\Archivefiles"
  
  $PreCountErrorFiles = ((Get-ChildItem $ErrorFiles | Measure-Object).Count)
  $PreCountArchivefiles = ((Get-ChildItem $Archivefiles | Measure-Object ).Count)
  
  Get-ChildItem $ErrorFiles  | Where  {$_.LastWriteTime –lt ((Get-Date).AddDays(-10) )}  | ForEach     { Remove-Item $_.FullName }
  Get-ChildItem $Archivefiles | Where  {$_.LastWriteTime –lt ((Get-Date).AddDays(-10) )}  | ForEach     { Remove-Item $_.FullName }
  
  $PostCountErrorFiles = ((Get-ChildItem $ErrorFiles | Measure-Object).Count)
  $PostCountArchivefiles  = ((Get-ChildItem $Archivefiles | Measure-Object ).Count)
  
  
  $str1 = "Number of files in " + $ErrorFiles.ToString() + " was " + $PreCountErrorFiles.ToString()     + " number of files deleted " + ($PreCountErrorFiles - $PostCountErrorFiles).ToString() + " and "  +     $PostCountErrorFiles.ToString() + " are left." + "`n"  +
  - "Number of files in " + $Archivefiles.ToString() + " was " + $PreCountArchivefiles.ToString() + "     number of files deleted " + ($PreCountArchivefiles - $PostCountArchivefiles).ToString() + " and "  +     $PostCountArchivefiles.ToString() + " are left." + "`n"
  
  write-host $str1
  </code></pre>
  
  <p>Thanks for you help!</p>