Instantly share code, notes, and snippets.

What would you like to do?
#needed for Set-ForegroundWindow
Write-Host "Installing PowerShell community modules..." -ForegroundColor Cyan
Install-Module -Name Pscx
Write-Host "Installing Kinect for Windows SDK 2.0..." -ForegroundColor Cyan
Write-Host "Downloading..."
$exePath = "$env:TEMP\KinectSDK-v2.0_1409-Setup.exe"
(New-Object Net.WebClient).DownloadFile('', $exePath)
Write-Host "Installing..."
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
Start-process $exePath
# it starts 2 processes, one is interactive, we need second
while ((Get-Process | ? {$ -eq "KinectSDK-v2.0_1409-Setup"}).Count -ne 2) {sleep 1}
# with less timeout it is unstable
sleep 40
# select interactive process (uses more memory) and set it's window active
$procs = Get-Process -Name KinectSDK-v2.0_1409-Setup
if ($procs[0].VM -gt $procs[1].VM) {$id = $procs[0].Id} else {$id = $procs[1].Id}
for ($i=0; $i -le 10; $i++) { Set-ForegroundWindow (Get-Process -id $id).MainWindowHandle; sleep 1}
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait(" "); sleep 1
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait(" ")
$installed = $false
Write-Host "Waiting SDK to be installed..."
$count = 0
while(!$installed -and $count -lt 90) {
$installed = (Get-Service | ? {$ -eq "KinectMonitor"}).Count -gt 0
if(!$installed) {Write-Host -NoNewline "."; sleep 1; $count++}
if(!$installed) {throw "Kinect for Windows SDK 2.0 was not installed"} else {Write-Host " OK" -ForegroundColor Green}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment