title: How can I set the save location of a file using powershell?
body: <p>I am trying to print a PDF as XPS, the script opens the PDF <code>Print Output As</code> screen and enters the correct name before sending the <code>ENTER</code> command to the window to save the file.</p>
  
  <p>How can I select the address bar to enter the desired path?  Or how can I change the default save path?</p>
  
  <p>EDIT:  Thank you for the feedback.  Here is the script:</p>
  
  <pre><code>function print_files($secure_pdf_dir){
      #Retrieves the name for the .xps files
      Get-ChildItem $secure_pdf_dir -Filter *.pdf -Recurse | Foreach-Object {
          #For each .pdf file in that directory, continue
          same_time $_.FullName
      }
  }
  ## The following function keeps checking for a new window called "Save Print Output As"
  ## When the window shows up, it enters the name of the file and press ENTER
  function enter_my_names($xps_dir, $fullname){
      $wshell = New-Object -ComObject wscript.shell;
      while($wshell.AppActivate('Save Print Output As') -ne $true){
          $wshell.AppActivate('Save Print Output As')
      }
      $basename = [io.path]::GetFileNameWithoutExtension($fullname)
      #This is where the name is actually entered
      $wshell.SendKeys($xps_dir\$basename)
      $wshell.SendKeys("{ENTER}")
     }
  
  ## The following function launches simultaneously a print job on the input file 
  ## and a function waiting for the print job to show up to name the file
  workflow same_time{
      Param(
          $fullname
      )
      parallel{
          Start-Process -FilePath $fullname –Verb Print -PassThru
          enter_my_names $xps_dir $fullname    
      }
  }
  #MAIN PROGRAM
  #Here the script saves your current printer as default
  $defprinter = Get-WmiObject -Query "Select * from Win32_Printer Where Default=$true"
  #Queries for a XPS printer
  $printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name='Microsoft XPS Document Writer'"
  #Sets the XPS printer as Default
  $printer.SetDefaultPrinter()
  #Starts the main job
  print_files($secure_pdf_dir)
  #Sets the old default printer back as default again
  $defprinter.SetDefaultPrinter()
  #This is a small delay to be sure everything is completed before closing Adobe Reader. You can probably shorten it a bit
  sleep 2
  #Finally, close Adobe Reader
  Get-Process "acrord32" | Stop-Process
  </code></pre>
  
  <p>It seems that the <code>$xps_dir</code> variable is not being passed into the function properly.</p>
  
  <p>Edit:  Error I get when trying to add $xps_dir to the enter_my_names function:</p>
  
  <pre><code>Microsoft.PowerShell.Utility\Write-Error : Cannot validate argument on parameter 
  'FilePath'. The argument is null or empty. Provide an argument that is not null or 
  empty, and then try the command again.
  At same_time:115 char:115
  + 
      + CategoryInfo          : NotSpecified: (:) [Write-Error], ParameterBindingValidati 
     onException
      + FullyQualifiedErrorId : System.Management.Automation.ParameterBindingValidationEx 
     ception,Microsoft.PowerShell.Commands.WriteErrorCommand
      + PSComputerName        : [localhost]
  </code></pre>