iTunes를 30초 빨리 감기로 만드는 itunesForward.ps1
이라는 PowerShell
스크립트가 있습니다:
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + 30
}
이 스크립트는 프롬프트 라인 명령으로 실행됩니다:
powershell.exe itunesForward.ps1
명령줄에서 인수를 전달하여 하드코딩된 30초 값 대신 스크립트에 적용되도록 할 수 있나요?
작동하는 것으로 테스트되었습니다:
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
위치 매개변수와 같은 $args
변수를 사용할 수도 있습니다:
$step=$args[0]
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + $step
}
처럼 호출할 수 있습니다:
powershell.exe -file itunersforward.ps1 15
를 사용하여 Powershell이 데이터 유형을 분석하고 결정하도록 합니다;
내부적으로 이를 위해 '변형'을 사용합니다...<br/gt;
를 사용하며 일반적으로 잘 작동합니다...
;
param( $x )
$iTunes = New-Object -ComObject iTunes.Application
if ( $iTunes.playerstate -eq 1 )
{ $iTunes.PlayerPosition = $iTunes.PlayerPosition + $x }
또는 여러 매개변수를 전달해야 하는 경우
param( $x1, $x2 )
$iTunes = New-Object -ComObject iTunes.Application
if ( $iTunes.playerstate -eq 1 )
{
$iTunes.PlayerPosition = $iTunes.PlayerPosition + $x1
$iTunes.<AnyProperty> = $x2
}
매입옵션 스크립트입니다 또는 CMD 에서 목욕 파일 (.bat)
Powershell Core *
pwsh.exe -NoLogo -ExecutionPolicy Bypass -Command "./Script.ps1 -Param1 Hello -Param2 World"
pwsh.exe -NoLogo -ExecutionPolicy Bypass -Command "path-to-script/Script.ps1 -Param1 Hello -Param2 World"
powershell.exe -NoLogo -ExecutionPolicy Bypass -Command "./Script.ps1 -Param1 Hello -Param2 World"
powershell.exe -NoLogo -ExecutionPolicy Bypass -Command "path-to-script/Script.ps1 -Param1 Hello -Param2 World"
hr > <;
전화를 powershell *
Powershell 코어 또는 Windows Powershell *
& path-to-script/Script.ps1 -Param1 Hello -Param2 World
& ./Script.ps1 -Param1 Hello -Param2 World
hr > <;
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)]
[System.String]
$Param1,
[Parameter(Mandatory=$True, Position=1, ValueFromPipeline=$false)]
[System.String]
$Param2
)
Write-Host $Param1
Write-Host $Param2
또한 직접 변수를 정의할 수 있습니다 다음 PowerShell 명령행을 실행하십시오 스크립트입니다. 아니했다고 정의된 변수를 볼 수 없다. 이 경우, t 수정할 수 있도록 내가 내 couldn& # 39 서명됨 스크립트입니다.
예: "' PS C:\temp>. 스테프시체 = $30 PS C:\temp>. .\itunesForward.ps1 "'
itunesforward.ps1 함께 있다.
"' 아이튠즈 (itunes) = 새 객체를 코모비치 이토네스지아프리카션 - $
if ($ 이토네스트 프라이어스테이트 - eq 1) { = $ 이토네스트 프라이어포지션 이토네스트 프라이어포지션 스테프시체 + $ $ } "'