title: Best way to execute powershell script ".ps1"
body: <p>what is the best way to execute .ps1 script?
  if I'm a user who has no idea about powershell, but I want to just double click the script and let it run.<br>
  could you please advise on the best practice?</p>
  
  <p>Thank you </p>
  
  <pre><code>[CmdletBinding()]
  Param(
      [Parameter(Mandatory = $False,        
          ValueFromPipeline = $True, 
          ValueFromPipelineByPropertyName = $True,         
          HelpMessage = "Provide Files Path.")]
      [string]$FilesPath = 'C:\Users\myusername\OneDrive - mycompany\mycompany\Sales &amp; Marketing\Sales Reports', 
      [Parameter(Mandatory = $False,
          ValueFromPipeline = $True,
          ValueFromPipelineByPropertyName = $True,
          HelpMessage = "Provide Sheet Name.")]
      [string]$SheetName = 'Expenses'
  )
  
  Try
  {
      $Files = Get-ChildItem -Path $FilesPath -Include *.xlsx, *.xls, *.xlsm -Recurse 
      $Counter = $Files.Count  
      $Array = @()
      $OutPutFilePath = (Join-Path $FilesPath -ChildPath "Exported-ExcelData.csv")
      Remove-Item -Path $OutPutFilePath -Force  -ErrorAction SilentlyContinue
      ForEach ($File In $Files)
      {                
          Write-Verbose -Message "Accessing File $($File.Name) and Exporting Data from Sheet $SheetName. Remaining $Counter Files." -Verbose 
          $Counter -= 1
          $AllData = Import-Excel -Path $File.FullName -WorksheetName $SheetName -NoHeader
          $i = 0 
          ForEach ($Data In $AllData)
          {
              $ArrayData = "" | Select-Object "P1", "P2", "P3", "P4", "P5", "P6"
              $ArrayData.P1 = $Data[0].P1
              $ArrayData.P2 = $Data[0].P2
              $ArrayData.P3 = $Data[0].P3
              $ArrayData.P4 = $File.Name
              $ArrayData.P5 = $File.FullName 
              $ArrayData.P6 = ($i += 1)
              $Array += $ArrayData
          }
      }
      $Array | Export-Csv -Path $OutPutFilePath -Append -NoTypeInformation 
  }
  Catch
  {
      $ErrorLog = "Error On " + (Get-Date) + ";$($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)"
      Write-Error "$($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)"    
  }
  Finally
  {
      Write-Host "Process has been completed!" -ForegroundColor Green
      Read-Host "Press any key to continue..."
  }    
  </code></pre>