1

I am trying to have powershell spit out the output file from a command to the current folder as I am trying to create a printer migration that can be run from a USB stick.

My command is simply: C:\Windows\System32\spool\tools\Printbrm.exe /b /f C:\Temp\Print

but I want the file to save to the directory that the script is being run from which can very between D: and and E: because the USB path changes on different computers in our organization.

Anyone able to help with this? I am guessing it is simple but can't figure it out.

1 Answers1

0

You can get the path containing the executing script from $MyInvocation:

$scriptFolder = $MyInvocation.MyCommand.Path | Split-Path -Parent

If you want the folder from which you're invoked it (since the title says "current directory"):

$currentFolder = (Get-Location).Path

To run your command and have it dump the output where the script is running:

$scriptFolder = $MyInvocation.MyCommand.Path | Split-Path -Parent
$printArgs = @("/b", "/f", $scriptFolder)
& "C:\Windows\System32\spool\tools\Printbrm.exe" $printArgs
WaitingForGuacamole
  • 3,744
  • 1
  • 8
  • 22