Wednesday, September 10, 2014

PowerShell - Change / Mute Audio Volume

Volume Mute Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]173)

Volume Down Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]174)

Volume Up Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]175)

** Each volume counter = 2%
Ex: Set Volume to 50%
Function Set-Speaker($Volume){ $ws = new-object -com wscript.shell;1..50 | % { $ws.SendKeys([char]174)};1..$Volume | % { $ws.SendKeys([char]175) } }
Set-Speaker(25)

PowerShell - Remote Add/Join Computers to domain

$domainAdminCred = Credential
$localAdminCred = Credential

$ScriptBlock = {
  param($domainAdminCred, $computer)
  $domain = "Domain"
  Write-Host "[processing '$computer' ...]"
  Add-Computer -DomainName $domain -Credential $domainAdminCred -OUPath "OU=group1,DC=testing,DC=com" -Restart -Force
}

$IP = "192.168.1.101"
$computer = "PC-01"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred
$IP = "192.168.1.102"
$computer = "PC-02"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred