powershellpathimportdata

Powershell Receive-File issue


Currently, I am using PowerShell version 5.1 in Sitecore 10 and attempting to use the cmdlet Receive-File in below script

$tempFolder =  "D:\temp\upload"
$filePath = Receive-File -Path $tempFolder -overwrite

if($filePath -eq "cancel"){
    exit
}

$importData = Import-CSV $filePath

$rowsCount = ( $importData | Measure-Object ).Count;
 
if($rowsCount -le 0){
    Remove-Item $filePath
    Write-Host "No Record found";
    exit
}
    
Write-Log "Bulk Update Started!";

but here $filePath is not returning the file path by using Receive-File. It works if directly gives file path but need to fetch from upload file option (Receive-File). Any assistance would be greatly appreciated.


Solution

  • Please refer https://sitecore.stackexchange.com/questions/35321/okclick-method-through-reflection-is-not-allowed-error-with-spe for it, it have the fix, you can add these config details and it should be working then.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:environment="http://www.sitecore.net/xmlconfig/environment/" xmlns:runInContainer="http://www.sitecore.net/xmlconfig/runInContainer/">
      <sitecore role:require="Standalone or ContentManagement">
        <reflection>
          <allowedMethods>
            <descriptor type="Spe.Client.Applications.UploadFile.PowerShellUploadFileForm" methodName="OKClick" assemblyName="Spe" hint="OK"/>
            <descriptor type="Spe.Client.Applications.UploadFile.PowerShellUploadFileForm" methodName="StartUploading" assemblyName="Spe" hint="StartUpload"/>
            <descriptor type="Spe.Client.Applications.UploadFile.PowerShellUploadFileForm" methodName="EndUploading" assemblyName="Spe" hint="EndUpload"/>
          </allowedMethods>
        </reflection>
      </sitecore>
    </configuration>
    

    It can either be a separate patch file as mentioned in the link or you can add new config with this detail and add into your custom config folder.