Powershell - Change System Volume

Ask and answer questions related to any type of OSA scripting.
Post Reply
Message
Author
Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Powershell - Change System Volume

#1 Post by Andre » Tue Dec 23, 2014 12:08 am

Sometimes, when playing on the PC, I need to turn the volume down, but then forget to set it back to 100% again, hence I miss the TTS voice giving me notifications.

I am trying to adjust the PC volume back to 100 % through PowerShell, but although it works in PowerGUI, I can't get it working in OSA.
I thought it was a permission issue in Win 7 64-Bit, so set the OSA Service to run as an Administrator, but nothing.

Anyone have any ideas? (My garage door stood open the whole night :shock: )

I am using this in PowerGui successfully:

Code: Select all

Function Set-Speaker($Volume)
    {$wshShell = new-object -com wscript.shell;1..50 | % {$wshShell.SendKeys([char]174)};1..$Volume | % {$wshShell.SendKeys([char]175)}}

#Volume goes in increments of 2, so 50 is 100%
Set-Speaker -Volume 50

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Powershell - Change System Volume

#2 Post by Automate » Tue Dec 23, 2014 6:03 am

Have your tried any of the methods discussed here?
http://stackoverflow.com/questions/2135 ... powershell

Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Re: Powershell - Change System Volume

#3 Post by Andre » Tue Dec 23, 2014 9:54 pm

Thanks Automate, I had seen that page and tried a couple of the methods already, but I had seemingly glanced over the reference to NirCmd. http://www.nirsoft.net/utils/nircmd.html

I downloaded it and it works perfectly from Powershell within OSA.

Code: Select all

nircmd.exe setsysvolume 65535
It also does a bunch of other useful automation stuff. :lol:

Post Reply