title: powershell download file from Get-PnPListItem
body: <p>Im new to scripting and powershell so bare with me.
  My goal is to connect to Sharepoint online, and download the latest file uploaded to the a specific site.</p>
  <p>Currently I am able to Connect to Sharepoint with Connect-PnPonline, then i use PnPListItem to query the file i need, but i am stuck at the last step to download the file.</p>
  <p>here is my code:</p>
  <pre><code>cls
  $SPOsite=&quot;https://example.sharepoint.com/sites/example&quot;
  $TargetFile=&quot;C:\example&quot;
  Connect-PnPOnline -Url $SPOsite -ClientId xxxxx-xxxxx-xxxxx-xxxx -ClientSecret secretsecret112233
  $ListItems = Get-PnPListItem -List Documents | select -last 1 
  $ctx= Get-PnPContext
  foreach ($item in $ListItems)
  {
          $file = $item.file
          $fileversions = $file.Versions
          $ctx.load($file)
          $ctx.load($fileversions)
          $ctx.ExecuteQuery()
          Write-Host $file.Name,$fileversions.VersionLabel
  }
  Get-PnPFile -Url &quot;https://example.sharepoint.com/sites/example&quot; -Filename $ListItems -Path $TargetFile -AsFile
  </code></pre>
  <p>Error message that i get is</p>
  <pre><code>Get-PnPFile : File Not Found.
  At \\cifs-share.example.org\Usershome\user\Desktop\PowerShell\dwnldSPfiles.ps1:20 char:1
  + Get-PnPFile -Url &quot;https://example.sharepoint.com/sites/example&quot; -Fi ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (:) [Get-PnPFile], ServerException
      + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.GetFile
  </code></pre>