如何将参数传递给PowerShell脚本? [英] How can I pass an argument to a PowerShell script?
本文介绍了如何将参数传递给PowerShell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个名为itunesForward.ps1
的PowerShell脚本,可使iTunes快进30秒:
There's a PowerShell script named itunesForward.ps1
that makes iTunes fast forward 30 seconds:
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + 30
}
通过提示行命令执行:
powershell.exe itunesForward.ps1
是否可以从命令行传递参数并将其应用到脚本中,而不是硬编码的30秒值?
Is it possible to pass an argument from the command line and have it applied in the script instead of the 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屋!
查看全文