2023-07-29 10:34:04 +02:00
|
|
|
*set-volume.ps1*
|
|
|
|
================
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2023-09-20 17:05:11 +02:00
|
|
|
This PowerShell script sets the audio volume to the given value in percent (0..100).
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2023-09-20 17:05:11 +02:00
|
|
|
PS> ./set-volume.ps1 [-percent] <Int32> [<CommonParameters>]
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2023-09-20 17:05:11 +02:00
|
|
|
-percent <Int32>
|
|
|
|
Specifies the volume in percent (0..100)
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
Required? true
|
|
|
|
Position? 1
|
|
|
|
Default value 0
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2023-09-20 17:05:11 +02:00
|
|
|
PS> ./set-volume.ps1 50
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2022-11-17 19:46:02 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2023-09-20 17:05:11 +02:00
|
|
|
Sets the audio volume
|
2022-11-17 20:02:26 +01:00
|
|
|
.DESCRIPTION
|
2023-09-20 17:05:11 +02:00
|
|
|
This PowerShell script sets the audio volume to the given value in percent (0..100).
|
|
|
|
.PARAMETER percent
|
|
|
|
Specifies the volume in percent (0..100)
|
2022-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
2023-09-20 17:05:11 +02:00
|
|
|
PS> ./set-volume.ps1 50
|
2022-11-17 20:02:26 +01:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
2023-09-20 17:05:11 +02:00
|
|
|
Param([Parameter(Mandatory=$true)] [ValidateRange(0,100)] [Int] $percent)
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
# Create the Windows Shell object.
|
|
|
|
$obj = New-Object -ComObject WScript.Shell
|
|
|
|
|
|
|
|
# First, set volume to zero.
|
2023-09-20 17:05:11 +02:00
|
|
|
for ([int]$i = 0; $i -lt 100; $i += 2) {
|
|
|
|
$obj.SendKeys([char]174) # each tick is -2%
|
|
|
|
}
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
# Raise volume to specified level.
|
2023-09-20 17:05:11 +02:00
|
|
|
for ([int]$i = 0; $i -lt $percent; $i += 2) {
|
|
|
|
$obj.SendKeys([char]175) # each tick is +2%
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of set-volume.ps1 as of 10/19/2023 08:11:42)*
|