The direct equivalent will probably be to use $args
to access the arguments passed in. So you can do $args[0]
to get the equivalent of %~1
for example.
The tilde ~
in %~1
removes surrounding quotes, which isn't something you need to worry about when reading from arguments or parameters in a PowerShell script.
Parameters
Instead of $args
you may want to explicitly define parameters for your script, which you can do with a param()
block at the top of the script. You can even take your start time as a parameter and then prompt if it's blank.
param(
$Path,
$Start,
$Destination
)
if (-not $Start) {
$Start = Read-Host -prompt "trim start (ex. 00:00:00)"
}
Start-Process ffmpeg -ArgumentList @(
"-i"
$Path
"-ss"
$Start
$Destination
)
Read-Host -Prompt "Press Enter to exit"
To call:
<script>.ps1 -Path path/to/source -Destination /path/to/destination -Start 12:34:56
(if you leave -Start
out, it will prompt)
Quick note that %~dnp
by itself may not be valid. Was there supposed to be a number there? Or a letter if you were using it in a FOR
loop? I'm going to ignore it for now and take a new parameter for the destination.
I've also changed the Start-Process
invocation to use an array form for the arguments, since I feel this is cleaner, but you can change it back to one big string if you like.
Read more about advanced functions to see how you can make parameters mandatory (which will automatically prompt for them if they're missing), validate the values, set the types, etc.
References