Last active
August 22, 2018 14:23
-
-
Save WimObiwan/78def2eb9b5c1254e5cbc12d7bd11e9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
cd <waar je het script wil zetten> | |
$url = 'https://gist.githubusercontent.com/WimObiwan/78def2eb9b5c1254e5cbc12d7bd11e9f/raw' | |
wget $url -OutFile 'PhoneApps.ps1' | |
. .\PhoneApps.ps1 | |
New-PhoneAppsShortcuts | |
#> | |
$PhoneApps = @{ | |
# Skype for Business | |
# ProcessName: Lync | |
# Path: C:\Program Files (x86)\Microsoft Office\Root\Office16\lync.exe | |
'lync' = { Start-Process (Join-Path ${env:ProgramFiles(x86)} 'Microsoft Office\Root\Office16\lync.exe') } | |
# 3CX | |
# ProcessName: 3CXWin8Phone | |
# Path: C:\ProgramData\3CXPhone for Windows\PhoneApp\3CXWin8Phone.exe | |
'3CXWin8Phone' = { Start-Process (Join-Path $env:ProgramData '3CXPhone for Windows\PhoneApp\3CXWin8Phone.exe') } | |
# Teams | |
# ProcessName: Teams | |
# Path: C:\Users\wdevos\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe" | |
'Teams' = { Start-Process (Join-Path $env:LOCALAPPDATA 'Microsoft\Teams\Update.exe') -ArgumentList '--processStart', 'Teams.exe'} | |
} | |
function Stop-PhoneApps { | |
[CmdletBinding()] | |
param ( | |
) | |
# Get processes | |
$processes = $PhoneApps.Keys | ForEach-Object { | |
Get-Process $_ -ErrorAction SilentlyContinue | |
} | |
# Try to close them gracefully | |
$processes | ForEach-Object { | |
$_.CloseMainWindow() | Out-Null | |
} | |
# Wait max 5 seconds | |
$processes | Wait-Process -Timeout 5 -ErrorAction SilentlyContinue | |
$processes | Where-Object { -not $_.HasExited } | ForEach-Object { | |
Stop-Process $_ -Force | |
} | |
} | |
function Start-PhoneApps { | |
[CmdletBinding()] | |
param ( | |
) | |
$PhoneApps.Values | ForEach-Object { | |
$cmd = $_ | |
try { | |
$cmd.Invoke() | |
} | |
catch { | |
Write-Error "Unable to start $cmd (Error $_)" | |
} | |
} | |
} | |
function New-PhoneAppsShortcuts { | |
[CmdletBinding()] | |
param ( | |
) | |
$script = $PSCommandPath | |
$desktop = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop) | |
$link = Join-Path $desktop 'Start-PhoneApps.lnk' | |
Remove-Item $link -ErrorAction SilentlyContinue | |
$WshShell = New-Object -comObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($link) | |
$Shortcut.TargetPath = "powershell.exe" | |
$Shortcut.Arguments = "-Command "". '$script'; Start-PhoneApps;""" | |
$Shortcut.Save() | |
$link = Join-Path $desktop 'Stop-PhoneApps.lnk' | |
Remove-Item $link -ErrorAction SilentlyContinue | |
$WshShell = New-Object -comObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($link) | |
$Shortcut.TargetPath = "powershell.exe" | |
$Shortcut.Arguments = "-Command "". '$script'; Stop-PhoneApps;""" | |
$Shortcut.Save() | |
$Shortcut = $null | |
$WshShell = $null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment