使用Powershell暂停spotify并使用任务计划程序播放音频

使用Powershell暂停spotify并使用任务计划程序播放音频,powershell,scheduled-tasks,spotify,Powershell,Scheduled Tasks,Spotify,我已经通过任务调度器通过powershell播放了一段声音。现在我想在播放我的音频之前停止所有其他音频。(主要是spotify,这就是我的重点。)我尝试使用PSSpotify模块,在powershell中执行时,它就像一个符咒,但当我从“Run”启动它时,它只播放我的音频。它不会停止spotify中的音乐。我可以直接终止spotify进程,但我更喜欢其他方式 我的剧本: if (Get-Process -Name spotify) {Invoke-Spotify -stop; Start-Sle

我已经通过任务调度器通过powershell播放了一段声音。现在我想在播放我的音频之前停止所有其他音频。(主要是spotify,这就是我的重点。)我尝试使用PSSpotify模块,在powershell中执行时,它就像一个符咒,但当我从“Run”启动它时,它只播放我的音频。它不会停止spotify中的音乐。我可以直接终止spotify进程,但我更喜欢其他方式

我的剧本:

if (Get-Process -Name spotify) {Invoke-Spotify -stop; Start-Sleep -s 1;}
(New-Object Media.SoundPlayer "Z:\Emil\lunch.wav").Play(); Start-Sleep -s 5; Exit;
我在运行和任务计划程序中键入的内容:

powershell.exe -windowstyle hidden -File "Z:\Emil\lunchen.ps1"

我认为您需要显式导入PSSpotify模块。您可以将其添加到ps1文件中,也可以在命令行中执行

显示您可以执行以下操作:

C:\>Powershell -Command "& {Import-Module PSSpotify}" -File "Z:\Emil\lunchen.ps1"
或者将
Import模块PSSpotify
调用放在脚本顶部也可以