/
monitor-teams.ps1
41 lines (33 loc) · 1.88 KB
/
monitor-teams.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$shelly = $env:ShellyWebCamLight
$nextShellyPoll = Get-Date
$profilePath = ($env:LOCALAPPDATA).Replace('\', '#')
$teamsApp = Get-AppxPackage -Name MSTeams
while ($true) {
$webcamOn = $false
try {
$webcamOn = (Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged\$($profilePath)#Microsoft#Teams#current#Teams.exe" -Name 'LastUsedTimeStop' -ErrorAction SilentlyContinue) -eq 0 `
-or (Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\$($teamsApp.PackageFamilyName)" -Name 'LastUsedTimeStop' -ErrorAction SilentlyContinue) -eq 0
}
catch { }
try {
if ((Get-Date) -gt $nextShellyPoll) {
$shellyOn = (((Invoke-WebRequest -Method GET "http://$($shelly)/rpc/Switch.GetStatus?id=0") | ConvertFrom-Json).output) -eq "True"
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH-mm-ss') ... new light status: $($shellyOn)"
$nextShellyPoll = (Get-Date).AddSeconds(60)
}
if (!($webcamOn) -and $shellyOn) {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH-mm-ss') ... switching OFF" -ForegroundColor DarkBlue
Invoke-WebRequest -Method GET "http://$($shelly)/rpc/Switch.Set?id=0&on=false"
$nextShellyPoll = Get-Date
}
if ($webcamOn -and !($shellyOn)) {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH-mm-ss') ... switching ON" -ForegroundColor Green
Invoke-WebRequest -Method GET "http://$($shelly)/rpc/Switch.Set?id=0&on=true"
$nextShellyPoll = Get-Date
}
}
catch {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH-mm-ss') ... PROBLEM with the web request - network down?" -ForegroundColor DarkRed
}
Start-Sleep -Seconds 1
}