# IWYOwnStatus # # reads the own lync status and Updates the IWY Light every second # param ( [string]$remoteip = "192.168.178.22", # IP to send to [int]$remoteudpport = 8899, # port to send to [int]$sourceudpport = 0 # SourcePort, 0 uses an available port ) if (-not (Get-Module -Name Microsoft.Lync.Model)) { try { Import-Module -Name (Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath "Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll") -ErrorAction Stop } catch { Write-Warning "Microsoft.Lync.Model missing. Install the Lync 2013 SDK http://www.microsoft.com/en-us/download/details.aspx?id=36824" break } } function set-iwycolor ($color) { write-host "Set-IWYLight: $color" Start-Sleep -Milliseconds 100 $udpClient.Send((0x42, 0x00, 0x55), 3, $remoteip, $remoteudpport) | out-null Start-Sleep -Milliseconds 100 $udpClient.Send((0x40, $color, 0x55), 3, $remoteip, $remoteudpport) | out-null } write-host "Initialize IWYLight" $error.clear() $bytearray = New-Object Byte[] 3 $udpClient = new-Object system.Net.Sockets.Udpclient($sourceudpport) $sentbytes = $udpClient.Send($bytearray, $bytearray.length, $remoteip, $remoteudpport) write-host "Set Color to White" $udpClient.Send((0x42, 0x00, 0x55), 3, $remoteip, $remoteudpport) | out-null Start-Sleep -Milliseconds 100 $udpClient.Send((0xc2, 0x00, 0x55), 3, $remoteip, $remoteudpport) | out-null Start-Sleep -Milliseconds 100 write-host "Verbinde Lync Client" $Client = [Microsoft.Lync.Model.LyncClient]::GetClient() if ($Client.State -eq "SignedIn") { Write-host ("Lync Client ist angemeldet als " + $Client.uri) $selfcontact = $client.Self.Contact $oldstatus="" while ($true) { $currentstatus = $selfcontact.GetContactInformation([Microsoft.Lync.Model.ContactInformationType]::Activity) if ($currentstatus -ne $oldstatus) { $oldstatus = $currentstatus write-host "Updating IWYLight" switch -regex ($currentstatus) { "Available|Verfügbar" {set-iwycolor 0x55} # green "Busy|Beschäftigt" {set-iwycolor 0xa0} #red "DoNotDisturb|Nicht stören" {set-iwycolor 0xc0} #yellow "TemporarilyAway|Gleich zurück" {set-iwycolor 0x80} #yellow "Nicht bei der Arbeit" {set-iwycolor 0x80} #yellow "Away|Abwesend" {set-iwycolor 0x80} #yellow "Offline|Offline" {set-iwycolor 0x80} #yellow "Am Telefon" {set-iwycolor 0x20} #yellow default {Write-warning ("Unknown Status" + $currentstatus) } } } write-host ("Current Status:" + $currentstatus) start-sleep -seconds 1 } } else { Write-Warning "Lync ist nicht gestartet. Ende" } $udpClient.Send((0x41, 0x00, 0x55), 3, $remoteip, $remoteudpport) | out-null Start-Sleep -Milliseconds 100 $udpclient.close()