【发布时间】:2019-04-06 04:43:00
【问题描述】:
我正在尝试创建音频切换。我以前写过它,但是新的操作系统和 dll 更新迫使我重写它,我以前使用的方法似乎不再起作用了。 所以一出门,我的第一行就吐出了这个错误:
$audio : The term '$audio' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At D:\audiochanger.ps1:1 char:1
+ $audio = Get-AudioDevice -playback
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: ($audio:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
但是如果我输入$audio = Get-AudioDevice -playback 然后调用$audio,它工作得非常好。怎么回事?
$audio = Get-AudioDevice -playback
$audio.Name
if ($audio.Name -eq 'Speakers (Realtek High Definition Audio)') {
set-audiodevice 1
} Else {
set-audiodevice 2
}
Get-AudioDevice -playback的输出
Index : 2
Default : True
Type : Playback
Name : Speakers (Realtek High Definition Audio)
ID : {0.0.0.00000000}.{2aa2a27b-4ebc-4355-bdf7-093a8f97ba46}
Device : CoreAudioApi.MMDevice
or
Index : 1
Default : True
Type : Playback
Name : Speakers (Logitech G533 Gaming Headset)
ID : {0.0.0.00000000}.{1f5d6b65-fe9b-4bda-9508-d1a204149395}
Device : CoreAudioApi.MMDevice
这是在 windows 10 和 powershell 5 上运行的。我以前的工作代码可以在这里找到:need to select an item based on the name in an array using powershell
【问题讨论】:
标签: powershell control-characters