Select Page

Change Voice Policy of Lync 2013 Response Group Workflow, Dialin, or any other service

There is two ways to change the Voice Policy with Lync 2013.

  • CmdLets
  • Active Directory (advanced)

First of all, we will se how to get the Voice Policy from an Application Endpoint (Workflow, Dialin etc…) :

Get-CsApplicationEndpoint -Identity "*WorkflowName*" | Select VoicePolicy
Get-CsApplicationEndpoint -Identity "*WorkflowName*" | FL *

So if you want to change the voice Policy of a Workflow with powershell, here is the cmdlet :

Get-CsApplicationEndpoint -Identity "*WorkflowName*" | GrantCsVoicePolicy -PolicyName "VPolicy-US-International"

Now we are going to be more “serious” by going to make changes in the Active Directory for the workflow itself.

First, depending on your environment, the RTC services folder can be found in different paths:

  • [Configuration]/Services/RTC Services/Application Contacts
  • [Domain Naming Context]/Services/Microsoft/RTC Services/Application Contacts

Once you’re in the path, search for the Active Directory Contact object that is your workflow, and modifies the attribute of msRTCSIP-UserPolicies.

It may have some entries like “0=123,1=6,7=2,…”

The “7=” is the voice Policy pointer. So to assign the correct voice Policy number to the Contact, Show the anchors of the voice policies in powershell and add it to the contact.

Powershell Voice Policy Anchor :

Get-CsVoicePolicy | select Anchor

This is working for all the policies.

Karl

Disable Close button in Powershell Window

I did some powershell scripting these days.

Disabled Window running script

Disabled Window running script

Someone asked me if it would be possible to avoid the user to close the powershell window while a script is running (logon or any other). After a few searches in the MSDN world, I was able to handle the window and send some parameters to it.

For this, I ask the user32.dll Library to disable the powershell window and to disable the button (close menu). To remove any undesired button, I set the Windows style to Toolbox.

I know the fact of disabling window will avoid any user input and click on any button, but as they asked me to disable the button, I dit it this way. So use the rest as know-how… 🙂

Knowing what I need to code, I will use some user32.dll methods :

  • GetSytemMenu
  • EnableMenuItem
  • SetWindowLongPtr
  • EnableWindow

Hope that this script can be useful to some admins!

Karl

Windows versions tested
Windows 2000
Windows XP
Windows 7 OK
Windows 8
Windows 8.1 Standard OK (Disabled window only)

 

Here is the script :

#Calling user32.dll methods for Windows and Menus
$MethodsCall = '
[DllImport("user32.dll")] public static extern long GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")] public static extern bool EnableMenuItem(long hMenuItem, long wIDEnableItem, long wEnable);
[DllImport("user32.dll")] public static extern long SetWindowLongPtr(long hWnd, long nIndex, long dwNewLong);
[DllImport("user32.dll")] public static extern bool EnableWindow(long hWnd, int bEnable);
'

#Create a new namespace for the Methods to be able to call them
Add-Type -MemberDefinition $MethodsCall -name NativeMethods -namespace Win32

#WM_SYSCOMMAND Message
$MF_GRAYED = 0x00000001L    #Indicates that the menu item is disabled and grayed so that it cannot be selected.
$MF_BYCOMMAND = 0x0               #Gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified, the MF_BYCOMMAND flag is the default flag.            
$MF_DISABLED = 0x00000002L #Indicates that the menu item is disabled, but not grayed, so it cannot be selected.
$MF_ENABLED = 0x00000000L #Indicates that the menu item is enabled and restored from a grayed state so that it can be selected.
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ms647636(v=vs.85).aspx

$SC_CLOSE = 0xF060
$SC_CONTEXTHELP = 0xF180
$SC_MAXIMIZE = 0xF030 
$SC_MINIMIZE = 0xF020 
$SC_TASKLIST = 0xF130
$SC_MOUSEMENU = 0xF090
$SC_KEYMENU = 0xF100
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

$GWL_EXSTYLE = -20
$GWL_STYLE = -16
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx

#WM_SETICON Message  -  http://msdn.microsoft.com/en-us/library/ms632643%28VS.85%29.aspx
$WM_SETICON = 0x0080;
$ICON_SMALL = 0;
$ICON_BIG = 1;

#Extended Window Styles
$WS_EX_DLGMODALFRAME = 0x00000001L
$WS_EX_NOACTIVATE = 0x08000000L
$WS_EX_TOOLWINDOW = 0x00000080L
$WS_EX_STATICEDGE = 0x00020000L
$WS_EX_WINDOWEDGE = 0x00000100L
$WS_EX_TRANSPARENT = 0x00000020L
$WS_EX_CLIENTEDGE = 0x00000200L
$WS_EX_LAYERED = 0x00080000
$WS_EX_TOPMOST = 0x00000008L
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx

#Get window handle of Powershell process (Ensure there is only one Powershell window opened)
$PSWindow = (Get-Process Powershell) | where {$_.MainWindowTitle -like "*Powershell*"}
$hwnd = $PSWindow.MainWindowHandle

#Get System menu of windows handled
$hMenu = [Win32.NativeMethods]::GetSystemMenu($hwnd, 0)

#Window Style : TOOLWINDOW
[Win32.NativeMethods]::SetWindowLongPtr($hwnd, $GWL_EXSTYLE, $WS_EX_TOOLWINDOW) | Out-Null

#Disable X Button and window itself
[Win32.NativeMethods]::EnableMenuItem($hMenu, $SC_CLOSE, $MF_DISABLED) | Out-Null
[Win32.NativeMethods]::EnableWindow($hwnd, 0) | Out-Null

Write-Host "Disabled!" -ForegroundColor Red 
sleep 5

#Enable X Button
[Win32.NativeMethods]::EnableMenuItem($hMenu, $SC_CLOSE, $MF_ENABLED) | Out-Null
[Win32.NativeMethods]::EnableWindow($hwnd, 1) | Out-Null

Write-Host "Enabled!" -ForegroundColor Green
sleep 2

Get-CsActiveCalls – Get Lync Mediation server active calls with powershell

Get-CsActiveCalls

Hi,

This is a simple script you can use to see which server has active calls (mediation).

This uses the Get-CsWindowsService cmdlet to get the RTCMEDSRV values. This can be useful if you need to restart a server.

If you need only one server, you can also use this command :

Get-CsWindowsService -Name RTCMEDSRV | select activitylevel

To launch the function, just write the function name followed by the computername :

Get-CsActiveCalls computer01,computer02,computer03,computer04

This will show you the active calls like in the picture.

A few modifications : powershell seems to keep all values from before, so we just clear the values after showing the object with Clear-Item.

Communication Server versions tested
Office Communication Server 2007
Microsoft Lync Server 2010 OK
Microsoft Lync Server 2013 OK

Here is the script :

 


function Get-CsActiveCalls {
	param (
        [parameter(Mandatory=$false)][array]$Computer = $env:computername
    )
 	$BeforeErrorActionPreference=$ErrorActionPreference
	$BeforeProgressPreference = $ProgressPreference

	$ErrorActionPreference="SilentlyContinue"
	$ProgressPreference = "SilentlyContinue"
	cls
	
	$DateTimeDone = (Get-Date).tostring()
	Write-Host "Calls state on " -NoNewline
	Write-Host $DateTimeDone -ForegroundColor Green
	
    foreach ($PC in $Computer) {
 
        $x = Get-CsWindowsService -Name RTCMEDSRV -ComputerName $PC | select -expandproperty activitylevel
        
		$obj = New-Object PSObject
        $obj | Add-Member NoteProperty "Computer" $PC #.ToString()
 
        $findOut = $x -match '.*Current Outbound Calls=(\d+),.*'
        if ($findOut) {
            $outbound = $matches[1]
            $obj | Add-Member NoteProperty "Outbound Calls" $outbound #.ToString()
        }
 
        $findIn = $x -match '.*Current Inbound Calls=(\d+),.*'    
        if ($findIn) {
            $inbound = $matches[1]
            $obj | Add-Member NoteProperty "Inbound Calls" $inbound #.ToString()
        }
		
		$obj
    }
	
	Clear-Item $matches
	Clear-Item $obj
	Clear-Item $x
	Write-Host "Press any key to continue ..." -ForegroundColor yellow
	$KeyDown = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	
	$ErrorActionPreference=$BeforeErrorActionPreference
	$ProgressPreference=$BeforeProgressPreference
}
Get-CsActiveCalls computer01,computer02,computer03,computer04

NetApp Powershell Manager

Hi there,

Another script I’ve been developping this week : Netapp Powershell Manager. Download here

If you want to launch it from a Windows client, ensure you have the RSAT from Microsoft installed on your computer, and that you are logged as a domain dns admin.

By launching the netappVserverManager.ps1 script, you see the front page as seen on the image from left.

You can choose between Cluster mode or 7-mode, but actually only the cluster mode works (7-mode will come soon).

The program check the version of Windows and let you go further if you’re running Windows 7 or 2008 R2. If not, the progam show an error and end.

If the programm cannot load the dataontap module, it will prompt you for download the powershell toolkit MSI. This will open an IE instance with the link to download the toolkit. Login with your netapp credentials, accept the eula and you’re clear to download the MSI!

After having installed the msi, relaunch the script. From there, you’ll be able to go further to the server connection process.

Enter the server IP or name, the password, and once you are connected, you’ll see the menu as view in the picture from the right.

Actually, the script can only show you some information and (most useful) bulk add dns hosts (A) records into the DNS server.

I’ll come soon with new functions. Don’t hesitate to leave a comment/suggestion.

Cheers,

Karl

 

 

Fenestrae Faxination Server Bulk User Import on Active Directory – Version 1.0

Fenestrae Bulk

Fenestrae Bulk

Hi all,

I just finished creating a useful script to bulk import Fenestrae Users into Active Directory.

This script only activates the FAX part of fenestrae, I will add the ability to set SMS, MMS and all features on Active Directory soon.

Download here : fenestraeCSV

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
#Requires -Version 2.0
[string] $FilenameTranscript = $MyInvocation.MyCommand.Name + " " + (hostname)+ " {0:yyyy-MM-dd hh-mmtt}.log" -f (Get-Date)
Start-Transcript -path .\$FilenameTranscript | Out-Null
$error.clear()

clear

Write-Host "##########################################################################"
Write-Host "#     Fenestrae Bulk user activation                                     #"
Write-Host "#                                                                        #" 
Write-Host "##########################################################################" 
Write-Host "#   Author      : Karl Bustamante                                        #" 
Write-Host "#   Date        : 08.02.2013                                             #" 
Write-Host "#   Version     : 1.0                                                    #" 
Write-Host "#   Comment     : This program is used to activate bulk users for        #"
Write-Host "#                 Fenestrae Faxination Server                            #" 
Write-Host "#   Modified by :                                                        #"
Write-Host "#   Date        :                                                        #"
Write-Host "#   Comment     :                                                        #"
Write-Host "#                                                                        #" 
Write-Host "##########################################################################" 
Write-Host " "

Write-Host "Press any key to continue ..." -ForegroundColor yellow
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

function criticalError{
Write-Host "Error" -ForegroundColor black -backgroundcolor red
Stop-Transcript
Write-Host "Press any key to continue ..." -ForegroundColor yellow
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}

#Variables

#Strings
$strCSVPath = ".\fenestraeusers.csv"			# CSV File path

# Detect correct OS here and exit if no match (we intentionally truncate the last character to account for service packs)
Write-Host "System Version (OS) : " -NoNewLine
Write-Host (Get-WMIObject win32_OperatingSystem).Version -NoNewLine

if ((Get-WMIObject win32_OperatingSystem).Version -notmatch '6.1.760'){
	Write-Host "..............................[    ERROR   ]" -ForeGroundColor red
	Write-Host "`nThis script requires a version of Windows Server 2008 R2, which this is not. Exiting...`n" -ForegroundColor Red
	Stop-Transcript
	Write-Host "Press any key to continue ..." -ForegroundColor yellow
	$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	Exit
} #end OS detection
Write-Host "..............................[     OK!    ]" -ForeGroundColor Green

# checking if csv path is ok
Write-Host " - Checking if CSV '$strCSVPath' is available " -NoNewLine 
if(Test-Path -PathType leaf -Path $strCSVPath)
{
    Write-Host ".....[     OK!    ]" -ForeGroundColor green
	Write-Host " - Reading data in $strCSVPath" -NoNewLine
	$csvUsers = Import-Csv -path '.\fenestraeusers.csv' -delimiter ';'
	Write-Host ".....................[     OK!    ]" -ForeGroundColor green
}
else
{
	Write-Host ".....[    ERROR   ]" -ForeGroundColor red
	Write-Error "`nFile not found"
	criticalError
}

# Function to test if AD module is available
Function Get-MyModule { 
	Param([string]$name) 
	if(-not(Get-Module -name $name)) 
	{ if(Get-Module -ListAvailable | Where-Object { $_.name -eq $name }) 
	{ Import-Module -Name $name 
	Write-Host "`nThe"  -NoNewLine
	Write-Host " <$name> "  -ForegroundColor yellow -NoNewLine
	Write-Host "module has been loaded!"

	} 
	else { Write-Host -BackgroundColor Red "`n<$name>" -NoNewLine 
	Write-Host " module has not been loaded " -BackgroundColor Red -ForegroundColor yellow
	criticalError
	}
	} # end if not module 
	else {
		Write-Host "`nThe" -NoNewLine
		Write-Host " <$name> "  -ForegroundColor yellow -NoNewLine
		Write-Host "module is already loaded!" } 
	}
Get-Mymodule -name "ActiveDirectory"

Write-Host "--------------------------------------------------------------------------" -ForegroundColor green
Write-Host "Press any key to continue ..." -ForegroundColor yellow
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host "--------------------------------------------------------------------------" -ForegroundColor green

#Users creation
foreach($User in $csvUsers)
{

$login = $user.samaccountname
$facsimileTelephoneNumber = $user.facsimileTelephoneNumber
$dir = $user.dir
$fenUMOurCSID = $user.fenUMOurCSID
$fenUMAllowChargecodeOverride = $user.fenUMAllowChargecodeOverride
$fenUMAllowCoversheetOverride = $user.fenUMAllowCoversheetOverride
$fenUMAllowedToSendFax = $user.fenUMAllowedToSendFax
$fenUMAllowedToSendFaxInt = $user.fenUMAllowedToSendFaxInt
$fenUMAllowedToSendSms = $user.fenUMAllowedToSendSms
$fenUMAllowedToSendSmsInt = $user.fenUMAllowedToSendSmsInt
$fenUMAllowOurCSIDOverride = $user.fenUMAllowOurCSIDOverride
$fenUMAllowSMSTemplateOverride = $user.fenUMAllowSMSTemplateOverride
$fenUMCoversheet = $user.fenUMCoversheet
$fenUMFileformat = $user.fenUMFileformat
$fenUMMailTemplate = $user.fenUMMailTemplate

	Write-Host "--------------------------------------------------------------------------" -ForegroundColor cyan
	Write-Host " samAccountName         : $login" -ForegroundColor cyan
	Write-Host " FAX Number             : $facsimileTelephoneNumber" -ForegroundColor cyan
	Write-Host " CSID                   : $fenUMOurCSID" -ForegroundColor cyan
	Write-Host " DIR Number proxyaddress: $dir" -ForegroundColor cyan
	Write-Host " Coversheet             : $fenUMCoversheet" -ForegroundColor cyan
	Write-Host " File Format            : $fenUMFileformat" -ForegroundColor cyan
	Write-Host " Mail Template          : $fenUMMailTemplate" -ForegroundColor cyan
	Write-Host " ChargeCode Override    : $fenUMAllowChargecodeOverride" -ForegroundColor cyan
	Write-Host " CoversheetOverride     : $fenUMAllowCoversheetOverride" -ForegroundColor cyan
	Write-Host " Send FAX               : $fenUMAllowedToSendFax" -ForegroundColor cyan
	Write-Host " Send FAX International : $fenUMAllowedToSendFaxInt" -ForegroundColor cyan
	Write-Host " Send SMS               : $fenUMAllowedToSendSms" -ForegroundColor cyan
	Write-Host " Send SMS International : $fenUMAllowedToSendSmsInt" -ForegroundColor cyan
	Write-Host " CSID Override          : $fenUMAllowOurCSIDOverride" -ForegroundColor cyan
    Write-Host " SMS Template Override  : $fenUMAllowSMSTemplateOverride" -ForegroundColor cyan

	Write-Host "$login..................................................[" -NoNewLine
	Write-Host "   Creating   " -ForegroundColor yellow -NoNewLine
	Write-Host "]" -NoNewLine

	if ($facsimileTelephoneNumber -ne ""){
		$a = "Set-ADUser " + $login + " -Replace @{facsimileTelephoneNumber='" + $facsimileTelephoneNumber + "'}"
		Invoke-Expression $a
	}
	if ($fenUMAllowChargecodeOverride -ne ""){
		$b = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowChargecodeOverride'='" + $fenUMAllowChargecodeOverride + "'}"
		Invoke-Expression $b
	}
	if ($fenUMAllowCoversheetOverride -ne ""){
		$c = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowCoversheetOverride'='" + $fenUMAllowCoversheetOverride + "'}"
		Invoke-Expression $c
	}
	if ($fenUMAllowedToSendFax -ne ""){
		$d = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowedToSendFax'='" + $fenUMAllowedToSendFax + "'}"
		Invoke-Expression $d
	}
	if ($fenUMAllowedToSendFaxInt -ne ""){
		$e = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowedToSendFaxInt'='" + $fenUMAllowedToSendFaxInt + "'}"
		Invoke-Expression $e
	}
	if ($fenUMAllowedToSendSms -ne ""){
		$f = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowedToSendSms'='" + $fenUMAllowedToSendSms + "'}"
		Invoke-Expression $f
	}
	if ($fenUMAllowedToSendSmsInt -ne ""){
		$g = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowedToSendSmsInt'='" + $fenUMAllowedToSendSmsInt + "'}"
		Invoke-Expression $g
	}
	if ($fenUMAllowOurCSIDOverride -ne ""){	
		$h = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowOurCSIDOverride'='" + $fenUMAllowOurCSIDOverride + "'}"
		Invoke-Expression $h
	}	
	if ($fenUMAllowSMSTemplateOverride -ne ""){	
		$i = "Set-ADUser " + $login + " -Replace @{'fen-UM-AllowSMSTemplateOverride'='" + $fenUMAllowSMSTemplateOverride + "'}"
		Invoke-Expression $i
	}	
	if ($fenUMCoversheet -ne ""){		
		$j = "Set-ADUser " + $login + " -Replace @{'fen-UM-Coversheet'='" + $fenUMCoversheet + "'}"
		Invoke-Expression $j
	}
	if ($fenUMFileformat -ne ""){		
		$k = "Set-ADUser " + $login + " -Replace @{'fen-UM-Fileformat'='" + $fenUMFileformat + "'}"
		Invoke-Expression $k
	}
	if ($fenUMMailTemplate -ne ""){		
		$l = "Set-ADUser " + $login + " -Replace @{'fen-UM-MailTemplate'='" + $fenUMMailTemplate + "'}"
		Invoke-Expression $l
	}
	if ($dir -ne ""){		
		$m = "Set-ADUser " + $login + " -Add @{proxyAddresses = '" + $dir + "'}"
		Invoke-Expression $m
	}
	if ($fenUMOurCSID -ne ""){		
		$n = "Set-ADUser " + $login + " -Replace @{'fen-UM-OurCSID'='" + $fenUMOurCSID + "'}"
		Invoke-Expression $n
	}	

	Write-Host "`b`b`b`b`b`b`b`b`b`b`b`b`b`b     OK!" -ForegroundColor green -NoNewLine
	Write-Host "     ]"
}

Write-Host "--------------------------------------------------------------------------" -ForegroundColor green
Stop-Transcript
Write-Host "--------------------------------------------------------------------------" -ForegroundColor green
Write-Host "Press any key to exit ..." -ForegroundColor yellow

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Lync Server 2010 – Beep before call

Hi all,

As per usual, this is a network issue. You can use Microsoft Network Monitor with port and IP filters to check connexions.

Normally, the issue is the following :

The client is making an outbound call, the call has 3 ways to process and will try the ways as follow :

  1. Internet (Edge) – The call ask the EDGE if someone with the following sip is connected trough him.
  2. PSTN – Your PSTN Gateway
  3. Voicemail – Your UM Exchange server

For any network reason (Switch, Router,Firewall,…), the client can reach the edge, but the edge can’t reach the client. This is causing several beeps before the call really begin.

Hope this helps!

Beeps before Lync call

Hi all,

As per usual, this is a network issue. You can use Microsoft Network Monitor with port and IP filters to check connexions.

Normally, the issue is the following :

The client is making an outbound call, the call has 3 ways to process and will try the ways as follow :

  1. Internet (Edge) – The call ask the EDGE if someone with the following sip is connected trough him.
  2. PSTN – Your PSTN Gateway
  3. Voicemail – Your UM Exchange server

For any network reason (Switch, Router,Firewall,…), the client can reach the edge, but the edge can’t reach the client. This is causing several beeps before the call really begin.

Hope this helps!