Jump to content

Mass Remove Internal Fax


CHBT

Recommended Posts

  • Most Valued User

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:$false

Version 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


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:$false

Version 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


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.