TimAhKin Posted March 3, 2017 #1 Share Posted March 3, 2017 I have something like this. I want to test with one user then try to apply to everyone using a for each. First I display the value then try to change it. Connect-IpPbx $userData = Get-IpPbxUserData -UserName "TestUser" Write-Host "Test User : $($userData.m_bRecordAllCalls)" Write-Host "Test User : $($userData.m_szRecordedCallsFolder)" $userData.m_bRecordAllCalls = 1 $userData.m_szRecordedCallsFolder = "D:\Recordings" Write-Host " -----------------------------" $userUpdateRec = $userData.m_bRecordAllCalls $userUpdateLoc = $userData.m_szRecordedCallsFolder Write-Host "$($userUpdateRec)" Write-Host "$($userUpdateLoc)" #Update-IpPbxUser -UserEntry $userRec #Set-IpPbxUserData -UserEntry "Testuser" -UserData $userData I want to change those two settings for the user. I have the new values but cannot update them. I keep getting errors and I'm not sure if I need to use Update-IpPbxUser or Set-IpPbxUserData. Any ideas? I think it's something easy and stupid that I'm missing. Cheers! Link to comment Share on other sites More sharing options...
TimAhKin Posted March 3, 2017 Author #2 Share Posted March 3, 2017 Like I said, it was something stupid. I used -UserEntry instead of -UserName. UserEntry accepts an object and UserName a string. Works fine now. Link to comment Share on other sites More sharing options...
Most Valued User Sebastian Dreier Posted March 3, 2017 Most Valued User #3 Share Posted March 3, 2017 Hello, take care when you do this for all IpPbx users. Inside a ForEach loop you should always prefer the Entry instead of the Name parameter. Otherwise the CPU load and the memory consumption of the IpPbx ConfigDataStore service could get very high. This could have a negative impact on your whole server (at least for a while). Here my recommendation (not tested in detail): [CmdletBinding()] param([int]$RecordAllCalls = 1, [string]$RecordedCallsFolder = "D:\Recordings", [string]$IpPbxServerAddress = "localhost", [string]$IpPbxUserName = "", [string]$IpPbxPassword = "") # Optional: Add parameter validation here # 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 } # 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/ Get-IpPbxUser | 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 = $_ # Get the user data via user entry # (better performance and take less resources on the IpPbx server) $userData = Get-IpPbxUserData -UserEntry $currentUser Write-Host "User '$($currentUser.Name)': $($userData.m_bRecordAllCalls) / $($userData.m_szRecordedCallsFolder)" # Change the values $userData.m_bRecordAllCalls = $RecordAllCalls $userData.m_szRecordedCallsFolder = $RecordedCallsFolder # Save changes Set-IpPbxUserData -UserEntry $currentUser -UserData $userData # If you want to ensure that the changes have been saved # correctly you have to call Get-IpPbxUserData again $userData = Get-IpPbxUserData -UserEntry $currentUser Write-Host "User '$($currentUser.Name)' updated: $($userData.m_bRecordAllCalls) / $($userData.m_szRecordedCallsFolder)" } # Do not forget to clean up the table after eating ;-) Disconnect-IpPbx Link to comment Share on other sites More sharing options...
TimAhKin Posted March 3, 2017 Author #4 Share Posted March 3, 2017 Thank you very much! It worked fine. Have an awesome weekend! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.