CHBT Posted March 17, 2017 #1 Share Posted March 17, 2017 Hi all, Is there a way to remove the internal fax number for all users via PowerShell? Thanks Link to comment Share on other sites More sharing options...
Most Valued User Sebastian Dreier Posted March 20, 2017 Most Valued User #2 Share Posted March 20, 2017 Hello CHBT, yes that this is possible and it is very easy. Version 1 without status messages # Load the IpPbx Powershell Module Import-Module IpPbx # Connect to the IpPbx Server on the localhost via Windows Authentication Connect-IpPbx # Get all internal numbers of all IpPbx users # Filter the result for internal FAX numbers # Remove the numbers WITHOUT confirmation # prompt and WITHOUT any status message Get-IpPbxInternalNumber | Where-Object { $_.IsFaxNumber -eq $true } | Remove-IpPbxInternalNumber -Confirm:$falseVersion 2 with status messages # Load the IpPbx Powershell Module Import-Module IpPbx # Connect to the IpPbx Server on the localhost via Windows Authentication Connect-IpPbx # Do action for all users # 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. $userEntry = $_ # Get all internal fax numbers of this user $internalFaxNumbers = Get-IpPbxInternalNumber -Entry $userEntry | Where-Object { $_.IsFaxNumber -eq $true } # Ensure that the user has at least one internal fax number # otherwise we skip this user and proceed with the next one if (!$internalFaxNumbers -or $internalFaxNumbers.Count -eq 0) { return } # Let's remove all the internal fax numbers of # this user WITHOUT confirmation prompt $internalFaxNumbers | ForEach-Object { # Save the current ForEach object # in a separate variable again. $internalNumberEntry = $_ # Status Output Write-Host "Removing internal fax number '$($internalNumberEntry.Number)' from user '$($userEntry.Name)'..." # Let's do it :-) Remove-IpPbxInternalNumber -Entry $internalNumberEntry -Confirm:$false } } Link to comment Share on other sites More sharing options...
CHBT Posted March 20, 2017 Author #3 Share Posted March 20, 2017 5 hours ago, Sebastian Dreier said: Hello CHBT, yes that this is possible and it is very easy. Version 1 without status messages # Load the IpPbx Powershell Module Import-Module IpPbx # Connect to the IpPbx Server on the localhost via Windows Authentication Connect-IpPbx # Get all internal numbers of all IpPbx users # Filter the result for internal FAX numbers # Remove the numbers WITHOUT confirmation # prompt and WITHOUT any status message Get-IpPbxInternalNumber | Where-Object { $_.IsFaxNumber -eq $true } | Remove-IpPbxInternalNumber -Confirm:$falseVersion 2 with status messages # Load the IpPbx Powershell Module Import-Module IpPbx # Connect to the IpPbx Server on the localhost via Windows Authentication Connect-IpPbx # Do action for all users # 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. $userEntry = $_ # Get all internal fax numbers of this user $internalFaxNumbers = Get-IpPbxInternalNumber -Entry $userEntry | Where-Object { $_.IsFaxNumber -eq $true } # Ensure that the user has at least one internal fax number # otherwise we skip this user and proceed with the next one if (!$internalFaxNumbers -or $internalFaxNumbers.Count -eq 0) { return } # Let's remove all the internal fax numbers of # this user WITHOUT confirmation prompt $internalFaxNumbers | ForEach-Object { # Save the current ForEach object # in a separate variable again. $internalNumberEntry = $_ # Status Output Write-Host "Removing internal fax number '$($internalNumberEntry.Number)' from user '$($userEntry.Name)'..." # Let's do it :-) Remove-IpPbxInternalNumber -Entry $internalNumberEntry -Confirm:$false } } Brilliant! Thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.