39 lines
861 B
Markdown
39 lines
861 B
Markdown
## Description
|
|
|
|
This function can be used to set the volume of your targets PC
|
|
|
|
## The Function
|
|
|
|
### [Set-Volume]
|
|
|
|
In this function we will create an object to allow us to use the Send Keys method to either raise or lower the volume using the following syntax
|
|
```PowerShell
|
|
Set-Volume 50
|
|
```
|
|
|
|
```PowerShell
|
|
Function Set-Volume
|
|
{
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[ValidateRange(0,100)]
|
|
[Int]
|
|
$volume
|
|
)
|
|
|
|
# Calculate number of key presses.
|
|
$keyPresses = [Math]::Ceiling( $volume / 2 )
|
|
|
|
# Create the Windows Shell object.
|
|
$obj = New-Object -ComObject WScript.Shell
|
|
|
|
# Set volume to zero.
|
|
1..50 | ForEach-Object { $obj.SendKeys( [char] 174 ) }
|
|
|
|
# Set volume to specified level.
|
|
for( $i = 0; $i -lt $keyPresses; $i++ )
|
|
{
|
|
$obj.SendKeys( [char] 175 )
|
|
}
|
|
}
|
|
``` |