如何传递参数给PowerShell脚本? [英] How to pass an argument to a PowerShell script?
本文介绍了如何传递参数给PowerShell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个名为的PowerShell
剧本 itunesForward.ps1
,使iTunes的快进30秒时:
There's a PowerShell
script named itunesForward.ps1
that makes the iTunes fast forward 30 seconds:
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + 30
}
它与提示行命令执行:
It is executed with prompt line command:
powershell.exe itunesForward.ps1
是否有可能通过命令行参数,并把它在脚本应用的硬codeD30秒值呢?
Is it possible to pass an argument from the command line and have it applied in the script instead of hardcoded 30 seconds value?
推荐答案
<击>未经测试的:击>测试:
param([Int32]$step=30) #Must be the first statement in your script
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + $step
}
与调用它
powershell.exe -file itunesForward.ps1 -step 15
这篇关于如何传递参数给PowerShell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文