Most Valued User KlausH Posted February 28, 2017 Most Valued User #1 Share Posted February 28, 2017 Hello everybody, I tried to set the number of LineKeys to two.Sometimes it works and sometimes not.Is there still another possibility?Here is my script: Import-Module ippbx Connect-IpPbx $users = Get-IpPbxGroupMember -GroupName "_Konfig-Gruppe" Foreach($user in $users) { # Read UserDataObject $UserDataObject = Get-IpPbxUserData -UserName $User.Name # Set LineKeys $UserDataObject.m_iNumberOfLineKeys = 2 # Store Information Set-IpPbxUserData -UserData $UserDataObject -UserName $User.Name } Link to comment Share on other sites More sharing options...
Most Valued User Sebastian Dreier Posted March 2, 2017 Most Valued User #2 Share Posted March 2, 2017 Hallo Klaus, ich habe mir mal etwas Zeit genommen und hierzu das folgende Skript erstellt (nur rudimentär gestestet - Nutzung auf eigene Gefahr): <# .SYNOPSIS Changes the number of lines for all users of a specific group to the given value. .PARAMETER GroupName Name of the group .PARAMETER NumberOfLineKeys Defines how many lines a user should have after the script was executed .PARAMETER IpPbxServerAddress IpPbx Server Address (IP Address or FQDN) - Default: localhost .PARAMETER IpPbxUserName Username of an IpPbx User which should be used for the IpPbx UserName/Password Authentication .PARAMETER IpPbxPassword Password of an IpPbx User which should be used for the IpPbx UserName/Password Authentication .INPUTS [string] $GroupName [int] $NumberOfLineKeys [string] $IpPbxServerAddress [string] $IpPbxUserName [string] $IpPbxPassword .OUTPUTS None .EXAMPLE Set-NumberOfLineKeys -GroupName "DemoGroup" -NumberOfLineKeys 2 Connects to the local IpPbx Server via Windows Authentication and changes the number of lines for all users of the group "DemoGroup" to the value 2. .EXAMPLE Set-NumberOfLineKeys -GroupName "DemoGroup" -NumberOfLineKeys 2 -IpPbxServerAddress vm-test01 Connects to the IpPbx Server "vm-test01" via Windows Authentication and changes the number of lines for all users of the group "DemoGroup" to the value 2. .EXAMPLE Set-NumberOfLineKeys -GroupName "DemoGroup" -NumberOfLineKeys 2 -IpPbxServerAddress vm-test01 -IpPbxUserName "Admin" -IpPbxPassword "test123" Connects to the IpPbx Server "vm-test01" via IpPbx UserName/Password Authentication and changes the number of lines for all users of the group "DemoGroup" to the value 2. #> [CmdletBinding()] param([Parameter(Mandatory=$true)][string]$GroupName, [Parameter(Mandatory=$true)][int]$NumberOfLineKeys, [string]$IpPbxServerAddress = "localhost", [string]$IpPbxUserName = "", [string]$IpPbxPassword = "") # Ensure that a group name was provided otherwise stop the script here if (!$GroupName) { Write-Error "A group name must be provided" -ErrorAction Stop } # Ensure that a valid number of line keys was provided otherwise stop the script here if (!$NumberOfLineKeys -or ` $NumberOfLineKeys -lt 1 -or ` $NumberOfLineKeys -gt 99) { Write-Error "The provided number of line keys is invalid. Allowed values are: 1-99" -ErrorAction Stop } # Load ippbx module Import-Module -Name ippbx -Verbose:$false # Ensure that server address is not empty if (!$IpPbxServerAddress) { $IpPbxServerAddress = "localhost" } # If username and password are provided we try to # logon via IpPbx Username/Password Authentication # Otherwise we use Windows Authentication if ($IpPbxUserName -and $IpPbxPassword) { $Credentials = New-Object System.Management.Automation.PSCredential $IpPbxUserName, (ConvertTo-SecureString -String $IpPbxPassword -AsPlainText -Force) Connect-IpPbx -ServerName $IpPbxServerAddress -UseIpPbxLogin -Credentials $Credentials } else { # Logon via Windows Authentication Connect-IpPbx -ServerName $IpPbxServerAddress } # Design Pattern Advice: # Internal script variables should always be in lowerCamelCase. # Script parameters should be in UpperCamelCase. # Never use terms like Object, String or Integer in variables (e.g. UserDataObject). # Get all user entries (objects) from the group $users = Get-IpPbxGroupMember -GroupName $GroupName -ErrorAction Stop # Developer Note: # I highly recommend the usage of the ForEach-Object commandlet # for ForEach loops. For more details please read the following article: # https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/08/getting-to-know-foreach-and-foreach-object/ $users | ForEach-Object { # Save the current ForEach object in a separate variable. # This leads to better readability and maintainability. # Furthermore the separate variable can also be used # in antoher inner ForEach loop. $currentUser = $_ Write-Verbose "Checking user '$($currentUser.Name)'..." # Ensure that the user has at least one internal number if ($currentUser.InternalNumberEntryCollection.Count -eq 0) { Write-Warning "User '$($currentUser.Name)' has no internal number. Line key configuration cannot be updated. Skipping user..." return } # We should only save the user data if it really was changed $userDataChanged = $false # Developer Note: # Always try to use the Entry parameters. # This leads to a better performance and less memory usage on the IpPbx Server. # Get UserData $userData = Get-IpPbxUserData -UserEntry $currentUser # Set number of line keys if not equal if ($userData.m_iNumberOfLineKeys -ne $NumberOfLineKeys) { Write-Verbose "User has $($userData.m_iNumberOfLineKeys) line keys. Updating..." $userData.m_iNumberOfLineKeys = $NumberOfLineKeys $userDataChanged = $true } # Generate a new empty line key array with the size of $NumberOfLineKeys $newLineKeyList = New-Object CLineKeySetting[] $NumberOfLineKeys # Check the line key settings array and update it if required if ($userData.m_LineKeySettings.Count -ne $NumberOfLineKeys) { Write-Verbose "User has $($userData.m_LineKeySettings.Count) line key settings. Updating..." # Copy existing lines into the new line key array # If there are more existing lines then the array # can take we will ignore these lines for ($i = 0; $i -lt $NumberOfLineKeys; $i++) { $newLineKeyList[$i] = $userData.m_LineKeySettings[$i] } Write-Verbose "Line key settings copy process completed" # If the array is not completely filled we # have to add new empty lines with default values for ($i = 0; $i -lt $newLineKeyList.Count; $i++) { if (!$newLineKeyList[$i]) { $newLineKeyList[$i] = New-Object CLineKeySetting $newLineKeyList[$i].WrapUpTimeout = 120 } } Write-Verbose "Line key settings array filled" # Overwrite the old list with the new one $userData.m_LineKeySettings = $newLineKeyList $userDataChanged = $true } # Check if changes have been made if (!$userDataChanged) { Write-Warning "User '$($currentUser.Name)' already has $($NumberOfLineKeys) line keys. Skipping user..." return } # Save UserData Set-IpPbxUserData -UserData $userData -UserEntry $currentUser Write-Host "User '$($currentUser.Name)' updated successfully" } Kind regards from Saigon, Vietnam Sebastian Dreier Set-NumberOfLineKeys.ps1 Link to comment Share on other sites More sharing options...
Most Valued User KlausH Posted March 3, 2017 Author Most Valued User #3 Share Posted March 3, 2017 Hallo Sebastian, danke es funktioniert. hatte mir das einfacher vorgestellt. VG Klaus Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.